0
$\begingroup$

Given three vectors $a, b,$ and $c$ on the unit circle, and given a positive direction of rotation (say counter clockwise), how can I compute a property $\mathcal{C}$ that determines whether $a, b,$ and $c$ are in cyclical order?

For this property, it would hold that $$ \mathcal{C}(a, b, c) = \mathcal{C}(b, c, a) = \mathcal{C}(c, a, b) = True, $$ (i.e. $True$ for any cyclical permutation), but $False$ otherwise.

A simple solution, i.e. using atan2 and comparing the angles would use lots of conditional statements (both in atan2 itself aswell as in the algorithm for $\mathcal{C}$). Instead, I am looking for a more algebraic solution.

An approach that feels correct is embedding the 2D-vectors into a 3D space and using the sign of the Triple Product, which satisfies the cyclical property nicely. But I couldn't manage to come up with a formula using the sign and the triple product without using many conditional expressions.

Here's a visual example:

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ You should decide whether Property is named C or P, to avoid confusion. Please edit the question accordingly. $\endgroup$ – xax May 10 at 14:20
  • $\begingroup$ Use atan2 to find out the angles. Once you have found them, assign them to 3 variables and just sort them. You'll immediately be able to find out if property is valid. $\endgroup$ – Ritam_Dasgupta May 10 at 14:24
3
$\begingroup$

I think computing area of triangle made by the three points using determinant method will be useful. It changes sign if order of the points is reversed.

Also note that for three points, you have six possible permutations, of which three will be in one direction and other three in opposite direction. The sign of area of triangle from determinant method can be used to separate them.

$\endgroup$
1
  • $\begingroup$ Perfect, thanks. Actually, if you see it as an embedding into 3d space by adding a $z=1$ component to each vector, this is exactly taking the triple product of the resulting vectors, which is the parallel I've been looking for. $\endgroup$ – Romeo Valentin May 10 at 14:46
1
$\begingroup$

Stand upright on the $xy$-plane at point $A$ and look towards point $B$. Now turn to look towards point $C$, never turning your back entirely to the circle; that is, turn less than $180^\circ$. I think you want to know if you turned left or turned right. By the so-called right-hand rule, the sign of the vector cross product of $\vec{B-A}$ and $\vec{C-A}$ should tell you. If it's positive, you turned left; if negative, right.

$\endgroup$
0
$\begingroup$

You can compute the angle of each one using atan2. Calling the angles $A,B,C$, first check if $C \gt A$. If not, add $2\pi$ to it. Then they are in order if $A \lt B \lt C$.

$\endgroup$

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.