Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the angle between two points of a circle?

I have the centerX and centerY value of the circle and radius. And now i have (x1, y1) point that lie on the circle. I want to know the angle of circle for the point.

I tried the below formula to get the angle of (x1, y1). But it is not giving generic solution.

radian = Math.Atan2(y1 - Cy, x1 - Cx);
angle = radian * (180 / Math.PI);

Please refer the screenshot for my requirement.

enter image description here

Anyone please let me suggest what i did wrong.?

like image 849
Bharathi Avatar asked Jan 04 '23 15:01

Bharathi


1 Answers

From the MSDN documentation page for Atan2, it returns a result between -180 and 180 degrees (-pi to pi radians). On the other hand, you require 0 to 360. To do this, simply add 360 to the final answer in degrees if it is negative.

radian = Math.Atan2(y1 - Cy, x1 - Cx);
angle = radian * (180 / Math.PI);
if (angle < 0.0) 
   angle += 360.0;
like image 58
meowgoesthedog Avatar answered Jan 18 '23 06:01

meowgoesthedog