# Calculate angle of a line at the point it intersects a circle

Given a line with end points $(x_1,y_1)$ $(x_2,y_2)$ and a circle centered at $(x_1,y_1)$ how do I calculate the angle of the line (in degrees) as it relates to the circle? If that doesn't make sense then please see my basic example below.

For the below examples I'm assuming $(x_1,y_1)$ is $(0,0)$ and the circle has a radius of 1.

$(x_2,y_2)$ -- (in degrees)

$(2,0)$ -- 0
$(0,2)$ -- 90
$(-2,0)$ -- 180
$(0,-2)$ -- 270

-
I'm pretty sure this was asked before, but I can't find the other question. –  Guess who it is. Sep 9 '11 at 1:23
@J.M. - This one: math.stackexchange.com/questions/59/…? –  Peter Sep 9 '11 at 3:44

## 1 Answer

It seems to me that you are just finding the angle of the line from the point to the center of the circle, with 0 indicating that the line is parallel to the positive x axis. In this case, you should always just move your circle to the origin and then calculate the angle with the positive x axis.

For example, suppose that your center is at $(x_1, y_1)$ and you want to calculate the angle wrt the right horizontal from the center of the circle of the point $(a,b)$. Then you pretend your circle is at the origin by finding the angle between $(a - x_1, b - y_1)$ and the positive x axis.

I will assume that you can do that - I would recommend drawing a right triangle, or using the dot product and inverse cosine.

-
Actually, once s/he has $(a - x_1, b - y_1)$, two-argument arctangent can then be used to get the answer. –  Guess who it is. Sep 9 '11 at 1:30