scipy.spatial.ConvexHull¶
-
class
scipy.spatial.ConvexHull(points, incremental=False, qhull_options=None)¶ Convex hulls in N dimensions.
New in version 0.12.0.
Parameters: points : ndarray of floats, shape (npoints, ndim)
Coordinates of points to construct a convex hull from
incremental : bool, optional
Allow adding new points incrementally. This takes up some additional resources.
qhull_options : str, optional
Additional options to pass to Qhull. See Qhull manual for details. (Default: “Qx” for ndim > 4 and “” otherwise) Option “Qt” is always enabled.
Raises: QhullError :
Raised when Qhull encounters an error condition, such as geometrical degeneracy when options to resolve are not enabled.
ValueError :
Raised if an incompatible array is given as input.
Notes
The convex hull is computed using the Qhull library.
Do not call the
add_pointsmethod from a__del__destructor.References
[Qhull] http://www.qhull.org/ Examples
Convex hull of a random set of points:
>>> from scipy.spatial import ConvexHull >>> points = np.random.rand(30, 2) # 30 random points in 2-D >>> hull = ConvexHull(points)
Plot it:
>>> import matplotlib.pyplot as plt >>> plt.plot(points[:,0], points[:,1], 'o') >>> for simplex in hull.simplices: ... plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
We could also have directly used the vertices of the hull, which for 2-D are guaranteed to be in counterclockwise order:
>>> plt.plot(points[hull.vertices,0], points[hull.vertices,1], 'r--', lw=2) >>> plt.plot(points[hull.vertices[0],0], points[hull.vertices[0],1], 'ro') >>> plt.show()
Attributes