1
$\begingroup$

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!

$\endgroup$
5
  • $\begingroup$ What do you mean by "whether a circular arc travels clockwise or counter-clockwise"? Are you thinking of the smaller arc determined by the given points? $\endgroup$ – Intelligenti pauca Nov 12 '15 at 16:35
  • $\begingroup$ No, the arc may be the larger arc. The arc starts at the starting point and ends at the end point going around the center point. $\endgroup$ – D. Waschow Nov 12 '15 at 16:49
  • $\begingroup$ But in that case how do you decide the arc direction? It could go always counterclockwise, for instance. $\endgroup$ – Intelligenti pauca Nov 12 '15 at 17:20
  • $\begingroup$ Maybe I wasn't clear how I stated it. Using a drawing compass, you put the metal point on the center. Then place the pencil end on the start point and draw around to the end point. Depending on which end point is the start and which is the end will determine the direction the compass travels. $\endgroup$ – D. Waschow Nov 12 '15 at 18:47
  • $\begingroup$ You should realize that one can "place the pencil end on the start point and draw around to the end point" in either direction. How do you decide that you have to draw clockwise, for instance? Could you possibly show a picture? $\endgroup$ – Intelligenti pauca Nov 12 '15 at 19:03
3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ The arc is determined by the start, center, and end points. It's not necessarily the smaller angle. The arc could start at Northeast and proceed counter-clockwise all the around to East, for example. $\endgroup$ – D. Waschow Nov 12 '15 at 16:51
  • $\begingroup$ And vector math is also beyond me. I was really hoping for a simple logic solution using the radian angles. $\endgroup$ – D. Waschow Nov 12 '15 at 16:53
  • $\begingroup$ I've edited my answer avoiding vectors. $\endgroup$ – Intelligenti pauca Nov 12 '15 at 17:23
  • $\begingroup$ Thanks for removing the vector math! I'll give your simplified version a go and see if it works in all situations. If you'd left the vectors up on the answer I might have been able to use this situation as a learning experience for vector math. :-) $\endgroup$ – D. Waschow Nov 12 '15 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.