Take the 2-minute tour ×
MathOverflow is a question and answer site for professional mathematicians. It's 100% free, no registration required.

Given a directed cycle in the plane I need to walk it and detect whether it is clockwise or counterclockwise.

My first idea is to gather the sum of the turn angles, where a "left" turn is a negative angle, and a "right" turn is a positive angle. If I go with this one, I need a good way to calculate the angle between two vectors, and also which sign this angle should have (+/-).

Even if I had the right tools to calculate the (+/-) angle I feel like this could be done simpler.c

share|improve this question
    
Looks like a homework problem. –  Tunococ Oct 29 '10 at 10:16
    
So it does! It's not, though. (depending on a fitting definition of homework) –  Andy Storck Oct 29 '10 at 10:24
    
Assuming the cycle is embedded: Walk along the cycle once to find any rightmost vertex, $v$. At $v$, the exiting edge is (above) below the entering edge iff the cycle is (counter) clockwise. –  Sam Nead Oct 29 '10 at 11:24
    
Ok, it is more precise to say that the entering and exiting edges form two angles, one of these angles is "to the left" and the arrangement of the edges about the left angle tells you what you want. –  Sam Nead Oct 29 '10 at 11:28

1 Answer 1

up vote 4 down vote accepted

The orientation of a triangle (clockwise/counterclockwise) is the sign of the determinant $\begin{bmatrix} 1&x_1&y_1\\\\ 1&x_2&y_2\\\\ 1&x_3&y_3 \end{bmatrix}$, where $(x_1,y_1), (x_2,y_2), (x_3,y_3)$ are the Cartesian coordinates of the three vertices of the triangle.

share|improve this answer
    
Let me get this straight. What you're saying is that I can check whether the angle between any two "connected" vectors in the cycle by viewing them as forming a triangle. That seems to work! (unless they're bearing the same direction of course) So my initial idea is not as bad as I thought? –  Andy Storck Oct 29 '10 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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