Wrap a Point Cloud in a Convex Hull#

Download Python source code | Download Jupyter notebook

Create a convex_hull() from a point cloud.

import numpy as np
import pyvista as pv
from pyvista import examples

Load a Point Cloud#

The download_horse_points() dataset is a dense scan of a horse statue. Subsample it to keep the hull geometry light.

PolyData (0x7fe6c8cfffa0)
  N Cells:    4000
  N Points:   4000
  N Strips:   0
  X Bounds:   -4.164e-02, 4.188e-02
  Y Bounds:   -9.133e-02, 9.140e-02
  Z Bounds:   -7.651e-02, 7.534e-02
  N Arrays:   0


Extract the Outer Hull#

Use the convex_hull filter on the points.

hull = cloud.convex_hull()

pl = pv.Plotter()
pl.add_points(
    cloud,
    color='black',
    point_size=6,
    render_points_as_spheres=True,
)
pl.add_mesh(hull, color='royalblue', opacity=0.4, show_edges=True)
pl.camera_position = pv.CameraPosition(
    position=(-0.32, 0.0032, -0.024),
    focal_point=cloud.center,
    viewup=(0, 0, 1),
)
pl.show()
convex hull

Inspect the Wrapped Surface#

The result is a closed surface enclosing every input point.

PolyData (0x7fe6e8346200)
  N Cells:    434
  N Points:   219
  N Strips:   0
  X Bounds:   -4.164e-02, 4.188e-02
  Y Bounds:   -9.133e-02, 9.140e-02
  Z Bounds:   -7.651e-02, 7.534e-02
  N Arrays:   0


Tags: filter

Total running time of the script: (0 minutes 0.213 seconds)

Gallery generated by Sphinx-Gallery