# Thread: Angle between two points on a circle

1. ## [SOLVED] Angle between two points on a circle

I'd like to calculate the angle between two points on a circle, in which the radius of the circle is known, as are the coordinates of the two points and the center point. The problem is similar to this one, except I don't want to be limited to one point being at the 12-o'clock position.

Known:
p1 - starting point on circle
p2 - ending point on circle
c - center point on circle
r - radius of circle

Calculate:
central angle

The incomplete solution I came up with is to calculate the distance between the two points first (lets call them p1 and p2):
d = sqrt((x2 - x1)^2 + (y2 - y1)^2)

With that, the angle can be calculated as (r is radius of the circle):
angle = 2asin(d/2r)

The problem with this solution is that it doesn't produce angles over 180 degrees. When it goes over 180 degrees it starts giving the minor angle again, which leaves me unable to determine if the degrees it is giving are clockwise or counter clockwise from the starting point. (Here's a demo showing how to calculate the central angle, and it also runs into the same problem I encountered. It doesn't seem to know how to calculate an angle greater than 180 degrees.)

In other words, I always want this to calculate the angle clockwise from the starting point (p1) to the end point (p2), so that it produces angles up to 360 degrees.

2. ## Inelegant solution

I found a somewhat bloated solution by doing some additional calculations. The name of the game is to check if P2 lies to the left or right (relative) to the line formed by P1 and the opposite side of the circle. To test this condition, you need to create a third point (we'll call it Pa) that lies anywhere along the starting heading:

1. Create a point somewhere on the heading line, an arbitrary distance d. Take heading, h, and subtract 180 degrees:
h1 = h - 180

Calculate Pa (x, y) using:
xa = x1 - d cos h1
ya = y1 - d sin h1

2. Calculate the lengths of all three lines in the triangle formed by P1-P2-Pa:

a = sqrt( (x2 - x1)^2 + (y2 - y1)^2) )
b = sqrt( (xa - x1)^2 + (ya - y1)^2) )
c = sqrt( (x2 - xa)^2 + (y2 - ya)^2) )

3. Now take the law of cosines and rearange the variables to isolate the angle C:
C = acos( (c^2 - a^2 - b^2) / (-2ab) )

4. This generates an angle C. If the angle C is acute, then just use the regular value generated by the equations in my first post above (angle, a value 0-180). If the angle C is obtuse, then use the calculation (360 - angle) to generate values > 180.

I find this pretty tedious, so if anyone has a more elegant solution to derive angles 0 to 360 without all this mumbo-jumbo that would be great.

3. I must really not understand this question.
Because, if you know the coordinates of any three points it is simple to find all the angles.
There is absolutely no reason to involve a circle.

Say $Aa_x,a_y)~,~Bb_x,b_y),~\&~Cc_x,c_y)" alt="Aa_x,a_y)~,~Bb_x,b_y),~\&~Cc_x,c_y)" /> then we can find the measure of $
\angle ACB$
.
$m(\angle ACB) = \arccos \left( {\frac{{\left( {a_x - c_x } \right)\left( {b_x - c_x } \right) + \left( {a_y - c_y } \right)\left( {b_y - c_y } \right)}}
{{\sqrt {\left( {a_x - c_x } \right)^2 + \left( {a_y - c_y } \right)^2 } \sqrt {\left( {b_x - c_x } \right)^2 + \left( {b_y - c_y } \right)^2 } }}} \right)$

4. Hi Plato,

The angle I was looking for was the central angle, I believe it's called, which is the angle formed by one point on the circle (p1) the center of the circle, and the other point (p2). Since all three points are known, I assume you are correct if your calculation above can produce angles > 180 degrees. Does it?

As it turns out, if you take the angle calculated in my second post above and multiply it by 2, it also comes up with a central angle between 0 - 360 degrees. This was completely by accident, but it does the trick, so the calculations in my first post are redundant. I think the reason it worked out has something to do with the property of central angles shown in this Java applet:
Central Angle Theorem - Math Open Reference

Originally Posted by Plato
I must really not understand this question.
Because, if you know the coordinates of any three points it is simple to find all the angles.
There is absolutely no reason to involve a circle.

Say $Aa_x,a_y)~,~Bb_x,b_y),~\&~Cc_x,c_y)" alt="Aa_x,a_y)~,~Bb_x,b_y),~\&~Cc_x,c_y)" /> then we can find the measure of $
\angle ACB$
.
$m(\angle ACB) = \arccos \left( {\frac{{\left( {a_x - c_x } \right)\left( {b_x - c_x } \right) + \left( {a_y - c_y } \right)\left( {b_y - c_y } \right)}}
{{\sqrt {\left( {a_x - c_x } \right)^2 + \left( {a_y - c_y } \right)^2 } \sqrt {\left( {b_x - c_x } \right)^2 + \left( {b_y - c_y } \right)^2 } }}} \right)$

5. No angle has a measure greater than $\pi\text{ or }180^o$.

6. ## angle versus arc

Originally Posted by Plato
No angle has a measure greater than $\pi\text{ or }180^o$.
Is that even true? The Wikipedia article talks about positive and negative angles of 325 degrees:
Angle - Wikipedia, the free encyclopedia

I take it your equation above is unable to produce anything greater than 180 degrees so you're trying to get me with some sort of semantic difference here between an angle and arc. Can an arc have >180 degrees? If that's the case, I'm looking for an arc between 0 and 360 degrees.

In any event, my equation above is able to deliver a thingamajig between 0 and 360 degrees. Problem solved.

7. ## Another solution

Hi all,

I actually ran into this, too. I needed to be able to find both the clockwise and counter clockwise degrees(radians) around a circle from one point on it to another. I tried to figure out bbagnall's solution, but didn't have much luck.

A post over at gamedev.net was pretty helpful though: Rotation with atan2() problem - GameDev.Net Discussion Forums

It uses atan2 pretty cleverly. Keep in mind that mine is a programming standpoint. Just thought I'd leave a comment since I've been working at this for days and this particular post has been on my browser at least that long.