How to draw a perpendicular line to another?

5 views (last 30 days)
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

Accepted Answer

Iain
Iain on 23 Aug 2013
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 Comment
hadis ensafi
hadis ensafi on 14 Jun 2022
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..

Sign in to comment.

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!