How to draw a perpendicular line to another?
5 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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
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 Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!