Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find angle of a point from center of circle

Tags:

java

geometry

If I have an image 720, 720 that looks like this..

enter image description here

How do I work out the angle of the touched x,y given that the center x and y are 360, 360 A lot of calculations I see for this assume the origin is 0,0 (which is top left) so I get incorrect results. I am assuming 0 is always to the top and not rotated.

like image 729
Kyros Avatar asked Jan 23 '12 07:01

Kyros


2 Answers

May be clearer this way:

(Math.toDegrees( Math.atan2(fromLeft - 360.0, 360.0 - fromTop) ) + 360.0) % 360.0

Adding a 360 degree turn and applying the modulo operator gives you the positive angle, which atan2 does not.

like image 59
minopret Avatar answered Nov 07 '22 22:11

minopret


Here is the general formula:

angle = atan2(mouseY - cirleCenterY, mouseX - circleCenterX);
like image 23
Sileria Avatar answered Nov 07 '22 20:11

Sileria