boolean - boolean cut/intersect/stitch meshes

Defines boolean operations for triangular meshes. Strictly speaking, boolean operations applies on sets, but considering the volumes delimited by their mesh envelopes, we can perform boolean operations on those volumes by manipulating only surface meshes.

This relies on a new intersection algorithm named syandana. It finds candidates for intersections using a spacial hashing of triangles over a voxel (see madcad.hashing). This is solving the problem of putting triangles in an octree. Also to avoid the increasing complexity of the operation with flat planes divided in multiple parallel triangles, the algorithm is implemented with a detection of ngons.

The syandana algorithm achieves intersections of meshes in nearly O(n) where usual methods are O(n**2)

After intersection, the selection of surface sides to keep or not is done through a propagation.

most common

pierce(m1, m2, selector=False) madcad.mesh.Mesh

cut the faces of m1 at their intersection with faces of m2, and remove the faces inside

selector decides which part of each mesh to keep

  • False keep the exterior part (part exclusive to the other mesh)

  • True keep the common part

boolean(m1, m2, selector=(False, True), prec=None) madcad.mesh.Mesh

execute boolean operation on volumes

selector decides which part of each mesh to keep

  • False keep the exterior part (part exclusive to the other mesh)

  • True keep the common part

union(a, b) madcad.mesh.Mesh

return a mesh for the union of the volumes. It is a boolean with selector (False,False)

../_images/boolean-union.png
difference(a, b) madcad.mesh.Mesh

return a mesh for the volume of a less the common volume with b It is a boolean with selector (False, True)

../_images/boolean-difference.png
intersection(a, b) madcad.mesh.Mesh

return a mesh for the common volume. It is a boolean with selector (True, True)

../_images/boolean-intersection.png

more advanced

intersectwith(m1, m2, prec=None) madcad.mesh.Web

Cut m1 faces at their intersections with m2. Returning the intersection edges in m1 and associated m2 faces.

m1 faces and tracks are replaced thus the underlying buffers stays untouched.

The algorithm is using ngon intersections and retriangulation, in order to avoid infinite loops and intermediate triangles.

booleanwith(m1, m2, side, prec=None) set

execute the boolean operation inplace and only on m1