Reputation: 45
lately I have been struggling with arcs and their direction. I have arc built on three points. Lets call them FirstPoint, MiddlePoint and LastPoint. I need to determine if they are going clockwise or counterclockwise. I tried the solution from here Is ARC clockwise or counter clockwise?. However, it gives me wrong results. Im stuck with something like that:
public bool IsClockwise()
{
Vector se = new Vector(LastPoint.X - FirstPoint.X, LastPoint.Y - LastPoint.Y);
Vector sm = new Vector(MiddlePoint.X - FirstPoint.X, MiddlePoint.Y - FirstPoint.Y);
double cp = Vector.CrossProduct(se, sm);
if (cp > 0)
{
return true;
}
else return false;
}
Any ideas?
Upvotes: 1
Views: 974
Reputation: 29051
Try this. In your sample, you calculate se
as
Vector se = new Vector(LastPoint.X - FirstPoint.X, LastPoint.Y - LastPoint.Y);
Note that the second term is always zero.
Also, your two vectors should be from the midpoint to the first point, and from the midpoint to the last point. I suppose you could use vectors from the first point to the mid point and last point, but that's really not how it's typically done. It just feels wrong.
public bool IsClockwise()
{
Vector se = new Vector(LastPoint.X - MiddlePoint.X, LastPoint.Y - MiddlePoint.Y);
Vector sm = new Vector(FirstPoint.X - MiddlePoint.X, FirstPoint.Y - MiddlePoint.Y);
double cp = Vector.CrossProduct(se, sm);
return cp > 0;
}
Upvotes: 1