Determine Direction of an Arc (CW/CCW)

7.3k Views Asked by At

I'm trying to write a function that will determine whether a circular arc travels clockwise or counter-clockwise.

Given the X,Y coordinates for the start point, center point, and end point I first calculate the angle in radians from the center point to the start and end points.

I thought if I subtracted the ending line angle from starting line angle I could determine if the direction of the arc like this:

if (angle1 - angle2 <= 0): # Clockwise
else: # Counter-Clockwise

This does work for any cases where the arc doesn't cross the zero-radians line. But if the arc crosses that line the logic doesn't work.

This Illustration shows that the arc S1-C-E1 works but S2-C-E2 doesn't. I'm pretty sure I've got the right idea, I'm just stuck on the logical bit.

I found another question here that seemed to be similar to what I'm trying to do, but its answer involved a matrix which, I'm sad to admit, I've never learned how to work with. I need an answer that I can easily translate into code or enter into a spreadsheet.

Thanks for any and all assistance!

1

There are 1 best solutions below

4
On BEST ANSWER

If your question is about the smaller arc determined by the three points $A$ (start point), $O$ (center point) and $B$ (end point) then you can compute $$ c=(A_x-O_x)(B_y-O_y)-(A_y-O_y)(B_x-O_x). $$

If $c>0$ the arc is counterclockwise, if $c<0$ it is clockwise, if $c=0$ then $A$, $O$ and $B$ are aligned.