Cutting a triangular mesh and keeping the pieces
When we use a plane to cut a triangular mesh, several cases can be considered. If there is a non-null intersection between the plane and a given triangle, there are mostly five different cases:
But depending on how many vertices of the triangle are above the cutting plane, the resultant polygon of cutting the triangle by the cutting plane may be a smaller triangle, as shown in the left in pale orange or a quad as shown on the right case.
But if we want to keep the resulting mesh as a triangular mesh, the quads that might be obtained will need to be converted into triangles too.
- The plane contains one vertex of the triangle: not very useful for cutting purposes if the rest of the triangle lays above the cutting plane and we want to keep all that is below.
- The plane contains two vertices of the triangle, then the intersection is a line segment but we will only keep that triangle if the other vertex is below the cutting plane.
- The plane contains three vertices of the triangle: that is a keeper.
- The plane does not contain any vertices of the triangle, but there is an intersection with two of the edges: this is what we will talk about today here.
- A fifth case can be considered when the plane contains one vertex but the two other are on opposite sides of the plane, and it can easily be incorporated to the previous case.
The following picture shows us a couple of triangles of a mesh that is going to be cut by a plane:
The dotted horizontal line represents the cutting plane. If we want to create a new mesh of all the model that lays below the cutting plane, the triangles shown will need to be divided in a top and a bottom part.But depending on how many vertices of the triangle are above the cutting plane, the resultant polygon of cutting the triangle by the cutting plane may be a smaller triangle, as shown in the left in pale orange or a quad as shown on the right case.
But if we want to keep the resulting mesh as a triangular mesh, the quads that might be obtained will need to be converted into triangles too.
We can split the quad into two triangles easily, but what may not be as easy to do is to maintain the proper winding order of the triangle nodes. As that is the base of many programs for determining the normal direction of the triangle, failing to restore the correct order for these new triangles will result in a messy mesh.
What we have to remember is that these new triangles obtained by dividing a quad share the same orientation (normal) as the original triangle they are coming from. So a simple thing to do can be to calculate the new normal for the new triangles and, if found too far away from the original normal, two vertices of the triangle can be swapped to restore the right winding order. That approach worked for me nicely.
Of course, another task that needs to be achieved to obtain a 2-manifold mesh is to cover the holes created by the cutting plane in the remaining mesh below, but that will be covered in an upcoming entry.
Comments