How do I make sure the order of my vertices are always clockwise when creating new triangles?

In 2D I’m trying to insert a new vertex in my mesh and creating new triangles using that new vertex sort of like the red vertices in the picture shown:

However, I’m having trouble with figuring out how to order the vertices in the triangles array so that they are ALWAYS, no matter what situation, clockwise and render properly.

You could start with a possible vertex ordering, like A, B, C and take the cross product of those edges (B-A) and (C-B). That will result in an arrow pointing straight out of the face in one of two possible directions. Depending, one of those will be the “good” direction. If the cross-product is going the wrong way, flip the order of verts, otherwise keep it.

3 Likes

Oh cool. I didn’t know cross product had its applications in 2D. I thought all this time it could only be used in 3D :face_with_spiral_eyes: