Filter löschen
Filter löschen

How to draw a perpendicular line to another?

2 Ansichten (letzte 30 Tage)
F Z
F Z am 23 Aug. 2013
Kommentiert: hadis ensafi am 14 Jun. 2022
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

Akzeptierte Antwort

Iain
Iain am 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 Kommentar
hadis ensafi
hadis ensafi am 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..

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink PLC Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by