Search code examples
formulaanglepoints

Find angle from two points formula


I have question about the formula to calculate the Angle between two points p1(x1,y1), p2(x2,y2).

I use this formula :

angle = arctan(y2-y1/x2-x1)

Can you explain, why y2,y1 and x2,x1 must be subtracted ?

Thanks


Solution

  • tan, sin, and cos are actually measuring the ratios between two edges of a 3-edged object aka a triangle.

    Hence in your case, to form that triangle, you will need the lengths of two edges. They are the lengths between y1 and y2, and x1 and x2.

    That is why you deduct y1 from y2 and x1 from x2.

    In fact, you have to ensure that the signs are correct too, else you will get a different angle as your answer.