The convex hull is the smallest convex polygon, in 2D, or polyhedron, in higher dimensions, that contains all the given points, with the resulting object's .vertices attribute giving the indices of the points that actually form the hull's boundary — most of the original points are typically interior points that end up not on the hull at all, since they're already enclosed by it. It's used for tasks like collision detection, finding the outer boundary of a scattered point cloud, and as a building block in various geometric algorithms.
1Understanding spatial.ConvexHull()
The convex hull is the smallest convex polygon, in 2D, or polyhedron, in higher dimensions, that contains all the given points, with the resulting object's .vertices attribute giving the indices of the points that actually form the hull's boundary — most of the original points are typically interior points that end up not on the hull at all, since they're already enclosed by it. It's used for tasks like collision detection, finding the outer boundary of a scattered point cloud, and as a building block in various geometric algorithms.
ConvexHull's .vertices gives only the boundary points that actually form the hull, in order — most of the input points are typically interior and won't appear in .vertices at all, since the hull only needs its extreme, outermost points to define its shape.
from scipy.spatial import ConvexHull
import numpy as np
points = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0.5, 0.5]])
hull = ConvexHull(points)
print(hull.vertices)2Practical Example
Here is a real-world application of spatial.ConvexHull() showing how it is used in production SciPy code.
from scipy.spatial import ConvexHull
import numpy as np
points = np.array([[0, 0], [2, 0], [2, 2], [0, 2]])
hull = ConvexHull(points)
print(hull.volume)3Best Practices
Follow these guidelines when working with spatial.ConvexHull():
1. Use ConvexHull to find the outer boundary of a scattered set of points, rather than manually determining which points are extreme
2. Access .vertices to get just the boundary-defining points, and .volume/.area for the hull's enclosed size, rather than recomputing these from raw coordinates yourself
3. Remember most input points are typically interior, not on the hull — don't assume every point will appear in the result
Tip: ConvexHull's .vertices gives only the boundary points that actually form the hull, in order — most of the input points are typically interior and won't appear in .vertices at all, since the hull only needs its extreme, outermost points to define its shape.
from scipy.spatial import ConvexHull
import numpy as np
points = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0.5, 0.5]])
hull = ConvexHull(points)
print(hull.vertices)