package scipy

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `ConvexHull
]
type t = [ `ConvexHull | `Object ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val create : ?incremental:bool -> ?qhull_options:string -> points:[> `Ndarray ] Np.Obj.t -> unit -> t

ConvexHull(points, incremental=False, qhull_options=None)

Convex hulls in N dimensions.

.. versionadded:: 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.

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 <http://www.qhull.org/>`__ 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 None A 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: simplicesgood. 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.

.. versionadded:: 1.3.0 area : float Area of the convex hull.

.. versionadded:: 0.17.0 volume : float Volume of the convex hull.

.. versionadded:: 0.17.0

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 <http://www.qhull.org/>`__.

Examples --------

Convex hull of a random set of points:

>>> from scipy.spatial import ConvexHull, convex_hull_plot_2d >>> 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(pointssimplex, 0, pointssimplex, 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(pointshull.vertices,0, pointshull.vertices,1, 'r--', lw=2) >>> plt.plot(pointshull.vertices[0],0, pointshull.vertices[0],1, 'ro') >>> plt.show()

Facets visible from a point:

Create a square and add a point above the square.

>>> generators = np.array([0.2, 0.2], ... [0.2, 0.4], ... [0.4, 0.4], ... [0.4, 0.2], ... [0.3, 0.6])

Call ConvexHull with the QG option. QG4 means compute the portions of the hull not including point 4, indicating the facets that are visible from point 4.

>>> hull = ConvexHull(points=generators, ... qhull_options='QG4')

The 'good' array indicates which facets are visible from point 4.

>>> print(hull.simplices) [1 0] [1 2] [3 0] [3 2] >>> print(hull.good) False True False False

Now plot it, highlighting the visible facets.

>>> fig = plt.figure() >>> ax = fig.add_subplot(1,1,1) >>> for visible_facet in hull.simpliceshull.good: ... ax.plot(hull.pointsvisible_facet, 0, ... hull.pointsvisible_facet, 1, ... color='violet', ... lw=6) >>> convex_hull_plot_2d(hull, ax=ax) <Figure size 640x480 with 1 Axes> # may vary >>> plt.show()

References ---------- .. Qhull http://www.qhull.org/

val add_points : ?restart:bool -> points:[> `Ndarray ] Np.Obj.t -> [> tag ] Obj.t -> Py.Object.t

add_points(points, restart=False)

Process a set of additional new points.

Parameters ---------- points : ndarray New points to add. The dimensionality should match that of the initial points. restart : bool, optional Whether to restart processing from scratch, rather than adding points incrementally.

Raises ------ QhullError Raised when Qhull encounters an error condition, such as geometrical degeneracy when options to resolve are not enabled.

See Also -------- close

Notes ----- You need to specify ``incremental=True`` when constructing the object to be able to add points incrementally. Incremental addition of points is also not possible after `close` has been called.

val close : [> tag ] Obj.t -> Py.Object.t

close()

Finish incremental processing.

Call this to free resources taken up by Qhull, when using the incremental mode. After calling this, adding more points is no longer possible.

val points : t -> Py.Object.t

Attribute points: get value or raise Not_found if None.

val points_opt : t -> Py.Object.t option

Attribute points: get value as an option.

val vertices : t -> Py.Object.t

Attribute vertices: get value or raise Not_found if None.

val vertices_opt : t -> Py.Object.t option

Attribute vertices: get value as an option.

val simplices : t -> Py.Object.t

Attribute simplices: get value or raise Not_found if None.

val simplices_opt : t -> Py.Object.t option

Attribute simplices: get value as an option.

val neighbors : t -> Py.Object.t

Attribute neighbors: get value or raise Not_found if None.

val neighbors_opt : t -> Py.Object.t option

Attribute neighbors: get value as an option.

val equations : t -> Py.Object.t

Attribute equations: get value or raise Not_found if None.

val equations_opt : t -> Py.Object.t option

Attribute equations: get value as an option.

val coplanar : t -> Py.Object.t

Attribute coplanar: get value or raise Not_found if None.

val coplanar_opt : t -> Py.Object.t option

Attribute coplanar: get value as an option.

val good : t -> Py.Object.t

Attribute good: get value or raise Not_found if None.

val good_opt : t -> Py.Object.t option

Attribute good: get value as an option.

val area : t -> float

Attribute area: get value or raise Not_found if None.

val area_opt : t -> float option

Attribute area: get value as an option.

val volume : t -> float

Attribute volume: get value or raise Not_found if None.

val volume_opt : t -> float option

Attribute volume: get value as an option.

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.

OCaml

Innovation. Community. Security.