bundles / scipy 1.17.1 / scipy / spatial / _qhull / ConvexHull
class
scipy.spatial._qhull:ConvexHull
source: /scipy/spatial/_qhull.cpython-314-x86_64-linux-gnu.so
Signature
class ConvexHull ( points , incremental = False , qhull_options = None ) Members
Summary
Convex hulls in N dimensions.
Extended Summary
Parameters
points: ndarray of floats, shape (npoints, ndim)Coordinates of points to construct a convex hull from
incremental: bool, optionalAllow adding new points incrementally. This takes up some additional resources.
qhull_options: str, optionalAdditional options to pass to Qhull. See Qhull manual for details. (Default: "Qx" for ndim > 4 and "" otherwise) Option "Qt" is always enabled.
Attributes
points: ndarray of double, shape (npoints, ndim)Coordinates of input points.
vertices: ndarray of ints, shape (nvertices,)Indices of points forming the vertices of the convex hull. For 2-D convex hulls, the vertices are in counterclockwise order. For other dimensions, they are in input order.
simplices: ndarray of ints, shape (nfacet, ndim)Indices of points forming the simplical facets of the convex hull.
neighbors: ndarray of ints, shape (nfacet, ndim)Indices of neighbor facets for each facet. The kth neighbor is opposite to the kth vertex. -1 denotes no neighbor.
equations: ndarray of double, shape (nfacet, ndim+1)[normal, offset] forming the hyperplane equation of the facet (see Qhull documentation for more).
coplanar: ndarray of int, shape (ncoplanar, 3)Indices of coplanar points and the corresponding indices of the nearest facets and nearest vertex indices. Coplanar points are input points which were not included in the triangulation due to numerical precision issues.
If option "Qc" is not specified, this list is not computed.
good: ndarray of bool or NoneA one-dimensional Boolean array indicating which facets are good. Used with options that compute good facets, e.g. QGn and QG-n. Good facets are defined as those that are visible (n) or invisible (-n) from point n, where n is the nth point in 'points'. The 'good' attribute may be used as an index into 'simplices' to return the good (visible) facets: simplices[good]. A facet is visible from the outside of the hull only, and neither coplanarity nor degeneracy count as cases of visibility.
If a "QGn" or "QG-n" option is not specified, None is returned.
area: floatSurface area of the convex hull when input dimension > 2. When input
pointsare 2-dimensional, this is the perimeter of the convex hull.volume: floatVolume of the convex hull when input dimension > 2. When input
pointsare 2-dimensional, this is the area of the convex hull.
Raises
: QhullErrorRaised when Qhull encounters an error condition, such as geometrical degeneracy when options to resolve are not enabled.
: ValueErrorRaised if an incompatible array is given as input.
Notes
The convex hull is computed using the Qhull library.
Examples
Convex hull of a random set of points:from scipy.spatial import ConvexHull, convex_hull_plot_2d import numpy as np rng = np.random.default_rng() points = rng.random((30, 2)) # 30 random points in 2-D hull = ConvexHull(points)✓
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-')✗
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()
✓
generators = np.array([[0.2, 0.2], [0.2, 0.4], [0.4, 0.4], [0.4, 0.2], [0.3, 0.6]])✓
hull = ConvexHull(points=generators, qhull_options='QG4')✓
print(hull.simplices) print(hull.good)✗
fig = plt.figure() ax = fig.add_subplot(1,1,1)✓
for visible_facet in hull.simplices[hull.good]: ax.plot(hull.points[visible_facet, 0], hull.points[visible_facet, 1], color='violet', lw=6) convex_hull_plot_2d(hull, ax=ax)✗
plt.show()
✓
Aliases
-
scipy.spatial.ConvexHull