Mesh clipping
- Peter Mortier
- Jan 18
- 1 min read
Updated: 2 days ago
In this example, you will learn how to perform mesh clipping using a plane. Mesh clipping is a technique in 3D modeling that divides a mesh using a clipping plane, creating a new mesh that retains only the elements on one side of the plane. This process is widely used to simplify models or focus on specific sections of a 3D object.
Using the Python code below, we first create a simple cube, that consists of 1 hexahedral element (element type hex8). This single hexahedral element is then subdivided into smaller hexahedral elements using the subdivide function. We then clip this mesh using a plane defined by a point p and a normal n. The resulting clipped mesh is shown in green in the figure below, while the original cube is depicted in transparent grey.
from hellotriangle import shapes
# generate cube
cube = shapes.cube(eltype='hex8')
# subdivide cube into smaller hex elements
hex = cube.subdivide(5)
# clip the mesh at a plane defined by a point p and a normal n
hexClipped = hex.clipAtPlane(p = [0.5, 0.5, 0.5], n = [1.0, 1.0, 1.0])
draw(hexClipped, show_edges = True, color = "#2BB786")
draw(hex, color="grey",opacity=0.3)
