필터 지우기
필터 지우기

How to draw a perpendicular line to another?

조회 수: 8 (최근 30일)
F Z
F Z 2013년 8월 23일
댓글: hadis ensafi 2022년 6월 14일
Hello,
Suppose i have a segment S1 defined by 2 points (x01,z01) and (x02, z02). The center of the segment is defines as (xm0, zm0). I want to plot the perpendicular line PL1 to S1 at (xm0, zm0) and find the intersection point of PL1 and the axis Y=0. The code is detailed below
a1=(z01-z02)/(x01-x02); %z1=a1*x1+b1 b1=z01-a1*x01; a2=-1/a1; % z2 perp to z1--> a2=-1/a1 b2=zm0-a2*xm0; %z2=a2*x2+b2
x=xm0:0.1:10; z2=a2*x+b2; xi=-b2/a2; %solve 0=a2*xi+b2 zi=a2*xi+b2;
h3=line([xm0,xi],[zm0,zi]); %trace du rayon principal
However, when i check the angle between my 2 perpendicular lines, it appears that it's not pi/2
O=(a2-a1)/(1-a1*a2); alpha=atan(O)*180/pi;
Any ideas please?
Fatzo

채택된 답변

Iain
Iain 2013년 8월 23일
xm0 = (x01+x02)/2; ym0 = (y01+y02)/2
m = (y2 - y1) / (x2-x1);
PLm = tan( atan(m)+pi/2);
PLc = ym0 - PLm*xm0;
%PL line eqn = y_PL = PLm * x_PL + PLc
x_at_yequalto0 = -PLc/PLm;
  댓글 수: 1
hadis ensafi
hadis ensafi 2022년 6월 14일
Hello.. thanks for your code.. I have this problem in 3D space! how can I calculate a perpendicular of a line in 3D space and in Specified plane? thanks a lot..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink PLC Coder에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by