0
\$\begingroup\$

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:

enter image description here

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.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

No matter where you place your new vertex, you will split your triangle into two triangles, each of which will take two consecutive vertices from the original triangle (in the same consecutive order) and one vertex will be the new insertion, replacing the vertex that we "removed".

Splitting along the edge between vertices P and Q with a new vertex N, you make two triangles, one that replaces P by N and one that replaces Q by N.

So let's say we have triangle A B C (in clockwise order), and we want to insert a new vertex N...

  • Between A & B:
    • N B C (replace A with N)
    • A N C (replace B with N)
  • Between B & C:
    • A N C (replace B with N)
    • A B N (replace C with N)
  • Between A & C:
    • N B C (replace A with N)
    • A B N (replace C with N)

One way to verify that this always has the same winding as the original triangle is to consider the cross product. Let's fix an ordering of the vertices A B C so that the new vertex N is inserted between A and B. The winding of this triangle is determined by the direction of the cross product (A - C) x (B - A) or (B - A) x (C - B) (among other equivalent formulations).

  • One new triangle's winding is (A - C) x (N - A), and (N - A) is parallel to (B - A) by construction, so the cross product points in the same direction as (A - C) x (B - A) and the winding is the same.

  • The other new triangle's winding is (B - N) x (C - B), and (B - N) is parallel to (B - A) by construction, so this cross product points in the same direction as (B - A) x (C - B), and so the winding is also the same.

\$\endgroup\$
1
  • \$\begingroup\$ That worked. Thanks! \$\endgroup\$ Oct 14, 2021 at 15:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .