# What is a clockwise ordering

This topic is 2595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have three unordered points and I want to find the normal. I need to get them into a clockwise ordering because I use a left hand coordinate system

My question is what is a clockwise ordering. How do you know if one point is more clockwise then another point?

I know what it looks like in my head but I wonder what is a good algorithm? All my point will be in quadrant 1. I also know the points are not collinear .

##### Share on other sites
A single point can't be clockwise or counterclockwise.

The term refers to the order of a set of 3 points; if you traverse them as list, in which direction would the path turn? There are only two options, cw or ccw.

You can find the normal of a triangle by taking the normalized cross product of the vectors p1-p0 and p2-p0 (where pn are the points of the triangle).

The practical implication is that if the normal of a screen-space triangle has a negative z component (assuming screen is the xy plane), it means that said triangle is backward facing with respect to the screen. This fact is very often used to hide back-facing triangles (which, given solid models, would not be visible anyway). The technique is known as "backface culling".

If you want to change the handedness of a triangle, just swap two of its points around.As for the "correct" handedness, you need to have some reference metric in order to determine which of the two normal directions is actually the one you want. Usually, you would inspect the orientation of other triangles adjacent to the one you're evaluating. However, not all models can follow same assumptions of correctness - for example, compare a "character" mesh and a "cave" mesh, and you can probably imagine that the "correct" orientation is model-dependent. This is why the triangle vertex ordering is usually done in the modeling software instead of an automatic process.

##### Share on other sites
There is nothing like "more clockwise" because of the periodicity of the circle. If you compute the normal from the cross-product of one of the possible sets of difference vectors, and compare that normal with a given reference direction vector, then you can decide whether the normal is more or less parallel (result of dot-product is positive) or else anti-parallel (result of dot-product is negative) with the reference vector. AFAIK, if you choose the look (i.e. camera forward) vector as reference, then you can define the anti-parallel case as where the vertices were ordered clockwise.

There is perhaps a more formal definition, but I think the above works as well.

##### Share on other sites
Your problem currently has no solution (without some extra information) -- Clockwise has no meaning without their being a 4th reference point.
e.g. given these ordered points on your monitor... 1 3 2...they are clockwise if you're looking at them from your point of view, but to someone behind your monitor they're counter-clockwise.

So the answer to which order is clockwise, the answer is: (1,2,3) and (1,3,2), but also it's not (1,2,3) and not (1,3,2)... the question can't be answered, unless you define where the observer is.

##### Share on other sites
• Three points define a triangle (unless collinear, please check if they are without making dangerous assumptions).
• A triangle lies in a plane.
• The triangle's plane has a well defined normal BUT you need to choose a direction (pointing into one halfspace or the other) arbitrarily.
• If you want to draw your triangle, ordering your vertices clockwise around the "bad" normal would give a back face, presumably culled automatically, and the opposite ordering (clockwise around the "good" normal) would make the triangle visible; you can test which normal direction points towards the screen plane.

##### Share on other sites
I already have a function for computing the normal, or rather the unnormalized normal. That I wrote a while ago. However, it needs to know the ordering to get the right normal direction. This is for dead reckoning ground clamping.

Am I right in assuming since all my points will be in quadrent 1 I can project my point into 2d and just compare x and z. If the point is down and right or equal and right from the last point then the ordering is correct.

My 4th point is the origin; since its ground clamping my map, starts at the origin.

(( edit) Just realized if you go into a deep pit its possible you would no longer be in quadrant 1. You could have negative y. )

##### Share on other sites
[font="Times New Roman"] [/font][font="Calibri"]My new idea is rather then sorting. I just test if the normal is negative in y and if it is I just flip the vector, should run faster.[/font]

[font="Times New Roman"] [/font]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634112
• Total Posts
3015580
×