if one point is further around a circle than another

Started by
7 comments, last by Endar 16 years, 3 months ago
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.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Advertisement
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.
Ra
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.
Quote:Original post by Vorpy
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.


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?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Quote:Original post by Endar
Quote:Original post by Vorpy
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.


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.
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.
Quote:Original post by jyk
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.


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?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
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.
Quote:Original post by Vorpy
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.


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
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

This topic is closed to new replies.

Advertisement