Asked by Amneh Alshawabka
on 20 Mar 2019

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?

Answer by Geoff Hayes
on 20 Mar 2019

Edited by Geoff Hayes
on 20 Mar 2019

Amneh - if a is (x1,y1) and b is (x2,y2) then let c be (x2,y1). With these three points, you should have a right-angled triangle. We can determine the opposite and adjancent as

opposite = abs(a(1) - c(1));

adjacent = abs(c(2) - b(2));

and so the angle is

myAngleDegrees = atand(opposite / adjacent);

(I think!)

Sign in to comment.

Answer by Amneh Alshawabka
on 20 Mar 2019

Thanks alot for your help . I'm a new Matlab user.

Actually i'm not sure how to creat a vertical line either from point a or b!! I want to caculate the angle between line ab and the verticale line from b to the ground as shown in the picture below.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Geoff Hayes (view profile)

Direct link to this comment:https://nl.mathworks.com/matlabcentral/answers/451187-calculate-the-angle-between-a-line-between-two-points-and-the-perpendicular-line#comment_683413

## Geoff Hayes (view profile)

Direct link to this comment:https://nl.mathworks.com/matlabcentral/answers/451187-calculate-the-angle-between-a-line-between-two-points-and-the-perpendicular-line#comment_683435

## Geoff Hayes (view profile)

Direct link to this comment:https://nl.mathworks.com/matlabcentral/answers/451187-calculate-the-angle-between-a-line-between-two-points-and-the-perpendicular-line#comment_683438

Sign in to comment.