# calculating angle in circle

How to calculate angle in a circle. Please see the diagram to get the idea what I want to calculate? I have origin of circle that is $(x_1,x_2)$. I have a point on circumstance of circle that is $(x_2,y_2)$. Also I know the radius of circle that is R.

How to calculate the angle between these two lines -- line starting from origin and ending on circumstance at 0 degree -- line starting from origin and ending on $(x_2,y_2)$. • Is the origin is at $(x_1,x_2)$ or $(x_1,y_1)$?? – Ramana Venkata Dec 27 '11 at 8:01
• Two-argument arctangent, $\arctan(x_2-x_1,y_2-y_1)$, works quite well here. – J. M. is a poor mathematician Dec 27 '11 at 9:29

I see you have a bunch of rep at SO, so in case you're looking for a practical, coding-oriented answer:

angle = atan2(y2-y1, x2-x1)


(which may need to be Math.atan2 or something such, depending on your language of choice). This usually maps down to a hardware operation specifically constructed for solving exactly this problem, and is therefore more efficient than the formulas involving standard trigonometric functions you find in the other answers.

The result comes out in radians, of course.

• thanks for searching about me and giving me exactly what I was looking for. – coure2011 Dec 28 '11 at 7:37

HINT:

Don't think of it as a circle. Instead, think of it as a triangle with three points $(x_1, y_1), \; (x_1 + R, y_1), \; (x_2, y_2)$. Then you can use any of the standard techniques for finding angles in a triangle, like the law of sines or cosines, etc.

The angle can be unambiguously computed as $$\theta=2\;\tan^{-1}\left(\dfrac{y_2-y_1}{x_2-x_1+\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}\right)$$ This can be seen in the following diagram: • This is how to compute atan2, as in @HenningMakholm's answer, when all you have is $\tan^{-1}$. – robjohn Dec 28 '11 at 23:27

Assuming the unlabeled line is parallel to the x-axis you could use the law of cosines.

Let us label each point $A(x_1,y_1)$, $B(x_2,y_2)$ and $C(x_1+r,y_1)$ where $r$ is the radius and $x_1,x_2,y_1,y_2$ are positioned as in you diagram.

The distance between $A$ and $B$ is given by $\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$ and the distance between $B$ and $C$ is $\sqrt{(x_2-x_1-r)^2+(y_2-y_1)^2}$.

Now, using the law of cosines which is $a^2=b^2+c^2-2bc\cos A$ we get $(x_2-x_1-r)^2+(y_2-y_1)^2=r^2+(x_2-x_1)^2+(y_2-y_1)^2-2\cdot r\cdot \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\cos A$

By solving for $\cos A$ we get: $$\cos A={(x_2-x_1-r)^2+(y_2-y_1)^2-r^2-(x_2-x_1)^2-(y_2-y_1)^2\over -2\cdot r\cdot \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}$$

Which simplifies to: $$\cos A={x_2-x_1\over \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}$$

Therefore the angle is: $$A=\cos ^{-1} \left( {x_2-x_1\over \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}\right )$$

I'm sorry if this was overly complicated for the question. There probably is some simpler way to do it, but it will look a lot less messy once you plug in the numbers.

Note: Please feel free to comment if I have made any careless mistakes.

You have only provided the radius and end point co-ordinates of a radius/line only. So, the information provided by you is insufficient for calculating the angle between those two lines. At least end point of another line should also known to find the angle between those two lines in circle.

• It seems clear from the diagram that the other line goes straight to the right, in the same direction as the $x$ axis. – Henning Makholm Dec 28 '11 at 2:37

Let $\theta$ denote the unknown angle. Then we can easily find $\tan(180 - \theta)$ by completing a triangle with vertices $(x_1, y_1)$ and $(x_2,y_2)$.

We have $\tan (180-\theta) = \frac{y_2-y_1}{x_2-x_1} = - \tan \theta$. Hence we know $\theta = \arctan (\frac{y1-y2}{x2-x1})$.