DataObjectFilters.convex_hull

DataObjectFilters.convex_hull#

DataObjectFilters.convex_hull(
*,
dimensionality: Literal[1, 2, 3, 'auto'] = 3,
progress_bar: bool = False,
) → PolyData[source]#

Compute the convex hull from this mesh’s points.

With vtk>=9.7, this uses vtkConvexHull. With older VTK, scipy (Qhull) is used instead for dimensionality=2 or 3; dimensionality=1 requires vtk>=9.7.

Added in version 0.49.

Parameters:
dimensionalityint | ‘auto’, default: 3

The dimensionality of the hull. If 'auto', the dimensionality is set to this mesh’s dimensionality, that is, points are not assumed to span all three dimensions. Auto-detection has a computational cost and is not enabled by default. Note that a 2D hull is computed from points projected onto this mesh’s best-fit plane, so requesting dimensionality=2 (or an auto-detected 2) for points that are not coplanar will discard information.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.PolyData

Surface mesh of the grid.

Examples#

Download Python source code | Download Jupyter notebook

Compute the convex hull of a 3D mesh.

>>> import pyvista as pv
>>> from pyvista import examples
>>> mesh = examples.download_cow_head()
>>> hull = mesh.convex_hull()

Plot the hull with the original input.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, color='red')
>>> _ = pl.add_mesh(hull, opacity=0.5, show_edges=True)
>>> cpos = pv.CameraPosition(
...     position=(9.159, 1.892, -4.015),
...     focal_point=(4.500, 1.731, -0.1015),
...     viewup=(0.08577, 0.9861, 0.1426),
... )
>>> pl.camera_position = cpos
>>> pl.show()
../../../_images/pyvista-DataObjectFilters-convex_hull-2611294913130d91_00_00.png

Compute the convex hull of two circle meshes comprising a MultiBlock.

>>> circle1 = pv.Circle(radius=0.5)
>>> circle2 = pv.Circle(radius=0.25).translate((1.0, 0.0, 0.0))
>>> mesh = pv.MultiBlock([circle1, circle2])
>>> hull = mesh.convex_hull(dimensionality=2)

Plot the hull with the original input.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, color='red')
>>> _ = pl.add_mesh(hull, opacity=0.5, show_edges=True)
>>> pl.view_xy()
>>> pl.show()
../../../_images/pyvista-DataObjectFilters-convex_hull-2611294913130d91_01_00.png