# Given face normal and vertices of a triangle, how to find the acyclic order of vertices?

I'm in the process of constructing a custom 3D triangle mesh. I found the vertices of the triangle in the 3D space and it's face normal. How do I find the acyclic order of vertices?

If I draw the vertices in the wrong order, I can't see some of the faces which should be visible when back face culling is enabled.

For a triangle with points p0, p1, and p2, and normal n, you’ll need to compare the vectors cross(p1 - p0, p2 - p0) and n. They should either point in the same direction, or in the opposite direction, for all triangles in your mesh.

Suppose your convention is that the vectors must point in the same direction.

The algorithm is simple. For each triangle, compute the following value:

dot(n, cross(p1 - p0, p2 - p0))


If the value is negative, swap p1 and p2.

• Perfect and clean solution!! Thank you so much. Understood that during the dot product of opposite normals gives negative scalar :) – cegprakash Mar 4 '14 at 8:42
• Hi, I'm getting NaN during my cross product. Any idea on how to fix this? – cegprakash Mar 4 '14 at 10:18
• Given that a cross product is only additions and multiplications, and assuming the implementation is correct, if a cross product results in NaN values it means that one of the initial vectors had a NaN component. Maybe you have uninitialised data in your triangle lists? – sam hocevar Mar 4 '14 at 16:54
• fixed.. my mistake :P – cegprakash Mar 4 '14 at 19:05