# if one point is further around a circle than another

This topic is 3915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm looking for a way to find if one 2d point is further around a the circumference of a unit circle than another, in the clockwise direction. This is pretty easy to do with angles, but since my input is going to be in the form of a 2d vector, I'm looking for a way to do it without using any trig functions.

##### Share on other sites
Assuming your origin is at (0, 0) you can just compare the results of atan2() for each point.

result = atan2(y0, x0) - atan2(y1, x1);

if (result >= 0.0)
{
// point 0 is further along the circumference
}
else
{
// point 1 is further along the circumference
}

Of course that's counterclockwise from the x-axis... You'll have to play with it to get the clockwise angle.

##### Share on other sites
Let c be the center of the circle
Let v1 = p1 - c
Let v2 = p2 - c

The sign of (v1.x * v2.y - v2.x * v1.y) is positive if p2 is counterclockwise from p1, negative if it is clockwise, and 0 if they are at the same angle from c.

##### Share on other sites
Quote:
 Original post by VorpyLet c be the center of the circleLet v1 = p1 - cLet v2 = p2 - cThe sign of (v1.x * v2.y - v2.x * v1.y) is positive if p2 is counterclockwise from p1, negative if it is clockwise, and 0 if they are at the same angle from c.

Hmmm, I must have done something wrong, because I'm getting the opposite of that. I put in the two vectors for 1 degree and 45 degress, and I get the result that indicates that 1 is clockwise from 45.

Is this a specific method, or part of a method for doing something else? How did you come up with this?

##### Share on other sites
Quote:
Original post by Endar
Quote:
 Original post by VorpyLet c be the center of the circleLet v1 = p1 - cLet v2 = p2 - cThe sign of (v1.x * v2.y - v2.x * v1.y) is positive if p2 is counterclockwise from p1, negative if it is clockwise, and 0 if they are at the same angle from c.

Hmmm, I must have done something wrong, because I'm getting the opposite of that. I put in the two vectors for 1 degree and 45 degress, and I get the result that indicates that 1 is clockwise from 45.
1 degree is clockwise (over the shortest arc) from 45 degrees, assuming a standard Cartesian plane. So your results do in fact match what Vorpy posted.

##### Share on other sites
The formula I posted for v1 and v2 is equivalent to sin(theta) * |v1| * |v2|, where theta is the angle between v1 and v2. Since the magnitude of v1 and v2 are always positive, the sign depends entirely on sin(theta), which is positive for counterclockwise angles and negative for clockwise angles. The formula is also referred to as a 2d version of the cross product, or the perp-product, since the result also corresponds to a cross product where both vectors were on the x-y plane and the result is the magnitude of the resulting vector which only has a z component. It's the perp-product because it is the dot product of one vector with a vector perpendicular to the other. It's also twice the signed area of a traingle with vertices at the origin and the two vector positions, or the signed area of a parallelogram.

##### Share on other sites
Quote:
 Original post by jyk1 degree is clockwise (over the shortest arc) from 45 degrees, assuming a standard Cartesian plane. So your results do in fact match what Vorpy posted.

Okay, this I don't seem to understand. An arc is a segment of the circumference of a circle, correct?

Now, if you take the position on the circle of an angle of 1 degree and an angle of 45 degrees, going from 45 degrees to 1 degree using the shortest arc would be backwards, not forwards, and isn't that counter-clockwise, not clockwise?

What am I not understanding?

##### Share on other sites
In mathematics, angles are conventionally measured counterclockwise. On the usual cartesian coordinate plane, positive x is to the right and 0 degrees and positive y is up and 90 degrees. This is just the most common convention: positive angles are counterclockwise. In some uses and fields, the convention might go the other way, like in clocks.

##### Share on other sites
Quote:
 Original post by VorpyIn mathematics, angles are conventionally measured counterclockwise. On the usual cartesian coordinate plane, positive x is to the right and 0 degrees and positive y is up and 90 degrees. This is just the most common convention: positive angles are counterclockwise. In some uses and fields, the convention might go the other way, like in clocks.

Really? When I was in school learning angles, we did it the other way ... well, okay, so it is doing exactly what I want, just not the way I thought. :D

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632633
• Total Posts
3007543
• ### Who's Online (See full list)

There are no registered users currently online

×