Search code examples
matlablinematlab-figureangle

How can I change the angle of a line in MATLAB?


I'm trying to compute two lines, with both having the same value for the first Y(1) , but with different lengths. How can I change the angle of the green line, without changing the first Y(1) value, in order to have the same inclination as the red one?

lines

Code:

xx4=[-4.07, -43.9450];
yy4=[1.25, 0.46];

xxlais=[37.1225 -35.93];
yylais=[1.25 0.46];

line(xx4,yy4,'Color','r')
hold on
line(xxlais,yylais,'Color','g')

Solution

  • First compute the expected slope:

    slope=(yy4(2)-yy4(1))/(xx4(2)-xx4(1))
    

    Then compute the new Y(2):

    yylais(2)=yylais(1)+slope*(xxlais(2)-xxlais(1))