I'm trying to get the heading angle from two points as shown below, within -180/180 range. Clockwise measures should be positive while counterclockwise should be negative.
;Assume a view from above:
;
; C
; |
; |
; |
; , A-------> (A's heading [A is facing this direction])
; , ' `
; , ' `
; D `
; `
; `
; B
float fAngle = A.GetHeadingAngle(B) ;fAngle will equal 45.0
float gAngle = A.GetHeadingAngle(C) ;gAngle will equal -90.0
float hAngle = A.GetHeadingAngle(D) ;hAngle will equal 150.0 (approx)
I've tried using atan2 and the difference in coordinates of the two points to get the angle:
headingangle = atan2(dy, dx) * (180.0 / MATH_PI);
but it doesn't give the expected results. for example:
expected HeadingAngle = -10.443440
actual HeadingAngle = 107.463173
Can any math gurus help?