pyvista_js.PolyData.clip

Contents

pyvista_js.PolyData.clip#

PolyData.clip(normal: str | tuple[float, float, float] = 'x', origin: tuple[float, float, float] | None = None, *, invert: bool = False) PolyData#

Clip the mesh with a plane.

This filter clips the mesh with a plane defined by a normal vector and an origin point. Points on one side of the plane are removed. It mirrors the PyVista clip filter API.

Note

The clipping is computed in JavaScript at render time by evaluating the signed distance of each vertex from the clip plane. Cells with all vertices on the clipped side are removed. vtk.js does not include a built-in clipping filter with the exact PyVista API, so this filter is implemented as a custom JavaScript pass.

Parameters:
  • normal (str or tuple of float, optional) – The normal vector of the clipping plane. Can be a string specifying a cardinal direction (‘x’, ‘y’, ‘z’, ‘-x’, ‘-y’, ‘-z’) or a 3-tuple of floats (nx, ny, nz). Default is ‘x’.

  • origin (tuple of float, optional) – The origin point of the clipping plane as (x, y, z). If not provided, defaults to the center of the mesh’s bounding box.

  • invert (bool, optional) – If True, flip the clipping direction to keep the part that would normally be removed. Default is False.

Returns:

A new mesh with clipped cells removed.

Return type:

PolyData

Examples

>>> import pyvista_js as pv
>>> sphere = pv.Sphere()
>>> clipped = sphere.clip(normal='x', origin=(0, 0, 0))
>>> isinstance(clipped, pv.PolyData)
True

Clip along the negative Y axis:

>>> clipped = sphere.clip(normal='-y')
>>> isinstance(clipped, pv.PolyData)
True

Clip with a custom normal vector:

>>> clipped = sphere.clip(normal=(1, 1, 0), origin=(0, 0, 0))
>>> isinstance(clipped, pv.PolyData)
True

Render the clipped mesh:

>>> clipped.plot()