mesh.Mesh.boolean#

Mesh.boolean(surf, op='+', fix_input=False, fix_output=False)#

Perform a boolean operation between two tri3 meshes.

Boolean operations between surface meshes require that both surfaces are closed (or watertight) and have consistent outward normals. Use check_triangle_mesh() to inspect meshes beforehand.

Parameters#

surfMesh (eltype=’tri3’)

Another surface Mesh.

op{‘+’, ‘-’, ‘*’}

The boolean operation to perform: union (‘+’), difference (‘-’) or intersection (‘*’).

fix_inputbool, default=False

If True, attempt to fix the input surfaces using fix_triangle_mesh() before performing the boolean operation.

fix_outputbool, default=False

If True, attempt to fix the resulting surface if the boolean produces a non-perfect mesh (holes, manifold issues, inconsistent normals).

Returns#

Mesh

A tri3 surface Mesh representing the volume union/difference/intersection.

Notes#

The result of boolean operations is not guaranteed to be a perfect closed manifold surface. After the operation, the resulting mesh can be checked using check_triangle_mesh() and a warning is emitted if problems are detected.

Examples#

>>> mesh1 = shapes.cuboid(eltype="tri3")
>>> mesh2 = mesh1.translate([0.5, 0.5, 0.5])
>>> out = mesh1.boolean(mesh2, op="-")
>>> print(out.enclosed_volume())
0.875
>>> print(out.check_triangle_mesh())
{'manifold': True, 'consistent_normals': True, 'watertight': True, 'valid_volume': True}