MathOverflow is a question and answer site for professional mathematicians. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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|cite|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
up vote 5 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|cite|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


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.