# Reordering vertices to make triangles CW/CCW

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

## Recommended Posts

Simple question I'm sure for anyone who knows how. I have an unordered triangle list, some defined in CW direction, others CCW. I understand this idea visually, but mathematically I'm stumped. How can you tell from the 3 vertex points in a triangle what the ordering is? How should I then go about reordering the triangle vertices? Any tips much appreciated,

##### Share on other sites
The three vertices of the triangle can be used to compute the face normal of the entire polygon. The direction of this normal will depend on the ordering of the vertices. What you need to know is which direction you expect the normal to point; if it points the opposite direction of what you expect, the vertices need to be reordered. Reordering can be accomplished by swapping any two of the vertices.

##### Share on other sites
Ah great, thats brought things together nicely. Didnt think t o just swap 2 vertices to reverse direction, most useful, thanks.

##### Share on other sites
Quote:
 Original post by DangerDaveI have an unordered triangle list, some defined in CW direction, others CCW. ... How can you tell from the 3 vertex points in a triangle what the ordering is?

The only way you can tell is if you compare the normal calculated from the vertexes to what the normal should be. If the normals match, then the order you assumed is correct. If one is the negative of the other, then the vertexes are in the opposite order.

If you don't have any information except the triangle list, then there is no way of knowing which are CW and which are CCW.

##### Share on other sites
Quote:
 Original post by DangerDaveAh great, thats brought things together nicely. Didnt think t o just swap 2 vertices to reverse direction, most useful, thanks.

Make sure that you remember that if you're using something like vertex buffers, you shouldn't be swapping the actual vertices, you should be swapping their indices in the index buffer.

Sounds simple enough to never forget? I did, for a while. [smile]

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 86
• 11
• 10
• ### Forum Statistics

• Total Topics
632972
• Total Posts
3009613
• ### Who's Online (See full list)

There are no registered users currently online

×