Boundary and size analysis
Summarize a point cloud by its outer boundary and calculate its geometric size.
SciPy · Class
ConvexHull computes the convex hull enclosing points in N-dimensional space. It returns an object with hull indices, facets, geometric measures, and optional incremental-update methods.
Constructing ConvexHull with an array of point coordinates runs Qhull to determine the enclosing convex polytope. The resulting object exposes the input-point indices defining the boundary, geometric measures, simplex facets, and optional incremental-update operations.
scipy.spatial.ConvexHull(points, incremental=False, qhull_options=None)| Name | Type | Description |
|---|---|---|
points | ndarray | Coordinates of points to construct a convex hull from; an array of floats with shape (npoints, ndim). |
incremental | bool, optional | Whether to allow adding new points incrementally; this uses additional resources. |
qhull_options | str, optional | Extra options passed to Qhull. The default is Qx when ndim > 4 and empty otherwise; Qt is always enabled. |
A ConvexHull object containing the computed hull and its geometric properties.
import numpy as np
from scipy.spatial import ConvexHull
points = np.array([
[0, 0], [2, 0], [2, 2], [0, 2], [1, 1]
])
hull = ConvexHull(points)
print(hull.vertices)
print(hull.area)
print(hull.volume)Builds a two-dimensional hull and prints its boundary-point indices, perimeter, and enclosed area.
Summarize a point cloud by its outer boundary and calculate its geometric size.
Maintain a hull while batches of observations arrive, avoiding an immediate full reconstruction.
Extract boundary facets and point indices for downstream computational-geometry operations.
ConvexHull computes the convex hull of points in N dimensions using Qhull. The input is an array shaped (npoints, ndim), and the returned object stores the hull geometry and related measurements.
Follow-up: How would you preserve boundary points that lie on a facet but are not vertices? Include Qc in qhull_options and inspect the coplanar attribute.
The points parameter is a floating-point array whose rows are coordinates. incremental enables adding points later, while qhull_options passes additional controls to Qhull; the default is Qx above four dimensions and empty otherwise.
Follow-up: What fixed Qhull behavior should be remembered when customizing options? Qt remains enabled regardless of qhull_options.
In two dimensions, area is the perimeter and volume is the enclosed area; in higher dimensions, they correspond to the hull's surface measure and content, respectively. The vertices attribute gives the input indices of hull vertices.
Follow-up: How can new data be incorporated without reconstructing immediately? Construct with incremental=True, call add_points, and call close when incremental processing is finished.
scipy.spatial.Delaunayscipy.spatial.Voronoiscipy.spatial.QhullErrorConvexHull.add_pointsConvexHull.close