algorithmsortinggeometrygeometric-arc

Identify start and end of arc out of three points/angles


I have three points that I know to be on a circle that represent the start, middle and end of an arc (a, m and b). I also have the angle of these points, from the positive X axis in an anti-clockwise direction, using atan2(y,x) of the three respective vectors from the centre to the points, so we have -pi < theta < pi.

I also know which of the points is m, and what I want to know is which of a and b is the clockwise end of the arc.

I can see that there are 8 ways the points can be arranged:

"East"       "West"     "East"
0          -pi | pi        0
---------------+-------------   
       a  m  b |           
          a  m | b         
             a | m  b 
               | a  m  b


       b  m  a |
          b  m | a
             b | m  a
               | b  m  a

where the first four have a as the "end" and b as the "start" and the latter four are the other way around. Bear in mind that orders about can wrap around at 0 and appear on the right or left, so sign is not helpful.

Is there a tidy way to work out which is the start and which is the end point? Other than laboriously checking relative values among each of the 8 options in a big, dense if/else-if block, that is.

Implementation language is Python, but this is not a language specific question!


Solution

  • If m is on the left side of the directed line segment from a to b, then a is the counterclockwise end; otherwise, it's the clockwise end.

    That is, take the left perpendicular of the vector ab, and find its dot product with am. If the dot product is positive, a is the CCW endpoint.

    Incidentally, the tidiest way to deal with angles is to avoid using them. Vectors and linear algebra out-tidy angles and trigonometry any day of the week.