MATLAB: Calculate the angle between a line (between two points) and the perpendicular line

julian williams

if point1 is a(x1,y1) and point 2 is b(x2,y2). I want to draw a vertical from point b in order to calculate the angle between the line ab and the verticle line.
I wrote this code but I think i can't get the verticle line correctly as I got the same value of the angle and i'm sure the angle value is not the same.
for i=1:size(a,1)
angle = atand(b(1,i) - a(1,i))-(b(2,i) - a(2,i)))
end
any one can help me please?
Clipboard-1.png

Best Answer

Maybe you mean:
angle = atand(b(1,:) - a(1,:)) - (b(2,:) - a(2,:)))
% ^???
without a loop. But here the number of parentheses does not match. I'm not sure which problem you want to solve.