Math formula needed for 360º navigation system

EFileTahi-A

Contributor
Joined
Aug 8, 2004
Messages
623
Location
Portugal / Barreiro
Since my trigonometry skills suck (I mean they really suck) I need help into translating coordinates (X,Y) into degrees.

Ok, lets assume we have a circle on the screen. The circle has naturally its center located at some x,y pos. Now, what I want is to click anywhere on the screen a return its current degree value based on a 360º navigation system related to the center of the mentioned circle.

Therefore, if I click at the right side of the circle's position it should return 90º degrees, if I click directly bellow the center of the circle it should return 180º degrees. At the top of it it should return 360 / 0 degrees.

The clicking area can be anywhere, not necessary inside the circle, it simply needs to return the relative direction from the circle's center towards the mouse' clicking position.
What is the math formula to achieve this?

Thank you so very much!
 
I got this PERFECT formula :D!

"bearingInDegrees = (atan2( x - x0, y0 - y ) / PI * 180 + 360) % 360,
where (x0,y0) is the centre coordinate, (x,y) is the click point and % is the modulus operator"

submitted by d-glitch at Experts Exchange!
 
Back
Top