Calculating angle from two co-ordinates

Started by
1 comment, last by __filip 17 years, 6 months ago
Given x1,y1 and x2,y2, how do you work out the angle of x2,y2 from x1,y1? Thanks for any help!
Advertisement
atan2(y2-y1,x2-x1)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
First off, an angle is something you have between two directions, not between two points.

However, I assume that you want the angle between the direction of the x-axis and the direction between the points. This is easy, if you program in c/c++ or similiar there is a function called atan2() which takes the difference in y as its first parameter and the difference in x as its second. It returns the angle in radians (between -pi and pi) (1 radian=180/pi degrees).

This topic is closed to new replies.

Advertisement