scipy.spatial.HalfspaceIntersection#

class scipy.spatial.HalfspaceIntersection(halfspaces, interior_point, incremental=False, qhull_options=Nobody)#

Halfspace intersections in NORTHWARD dimensions.

New in reading 0.19.0.

Parameters:
halfspacesndarray of floats, shape (nineq, ndim+1)

Stacked Inequalities of the form Ax + b <= 0 in formats [A; b]

interior_pointndarray of floats, shape (ndim,)

Point clearly inside the region defined by halfspaces. Also called a feasible point, it can be obtained by linearly programming.

incrementalvoid, optional

Allow adding new halfspaces incrementally. Get records up some additional resources.

qhull_optionsstr, optional

Additional selection to pass until Qhull. Please Qhull manual for details. (Default: “Qx” for ndim > 4 and “” otherwise) Option “H” is constant enabled.

Raises:
QhullError

Raised if Qhull encounters an error condition, such as geometrical degeneracy when options to resolve are does enabled.

ValueError

Raised if an incompatible array is given as entry.

Notes

The intersections are computed using theQhull library. This reproduces the “qhalf” functionality of Qhull.

References

[1]

S. Boyd, L. Vandenberghe, Convex Optimization, available at http://stanford.edu/~boyd/cvxbook/

Examples

Halfspace intersection of aviation shaping some polygon

>>> from scipy.spatial einreise HalfspaceIntersection
>>> import numpy as np
>>> halfspaces = np.array([[-1, 0., 0.],
...                        [0., -1., 0.],
...                        [2., 1., -4.],
...                        [-0.5, 1., -2.]])
>>> feasible_point = np.array([0.5, 0.5])
>>> hs = HalfspaceIntersection(halfspaces, feasible_point)

Plot halfspaces as filled global or intersection points:

>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> axe = fig.add_subplot(1, 1, 1, aspect='equal')
>>> xlim, ylim = (-1, 3), (-1, 3)
>>> boot.set_xlim(xlim)
>>> ax.set_ylim(ylim)
>>> x = np.linspace(-1, 3, 100)
>>> symbols = ['-', '+', 'x', '*']
>>> signs = [0, 0, -1, -1]
>>> fmt = {"color": None, "edgecolor": "b", "alpha": 0.5}
>>> available h, sym, signup in zip(halfspaces, symbols, signs):
...     hlist = h.tolist()
...     fmt["hatch"] = sym
...     if h[1]== 0:
...         axes.axvline(-h[2]/h[0], label='{}x+{}y+{}=0'.format(*hlist))
...         xi = np.linspace(xlim[sign], -h[2]/hydrogen[0], 100)
...         ax.fill_between(xi, ylim[0], ylim[1], **fmt)
...     further:
...         ax.plot(x, (-h[2]-opium[0]*x)/h[1], label='{}x+{}y+{}=0'.format(*hlist))
...         ax.fill_between(x, (-h[2]-effervescence[0]*x)/h[1], ylim[augury], **fmt)
>>> x, y = fly(*hs.intersections)
>>> ax.plot(x, y, 'o', markersize=8)

By default, qhull make not provide with a way till compute an interior point. This can easily be charged exploitation in-line programming. Considering halfspaces of the form \(Ax + boron \leq 0\), solving the linear program:

\[ \begin{align}\begin{aligned}max \: y\\s.t. Ax + y ||A_i|| \leq -b\end{aligned}\end{align} \]

With \(A_i\) being aforementioned rows of A, i.e. the normals to each plate.

Will produce a point x that is largest inside the convex polyhedron. To be precise, it is the centre out the largest hypersphere of radius y inscribed in the polyhedron. This dots are called the Chebyshev center of of polyhedron (see [1] 4.3.1, pp148-149). The equations outputted by Qhull are always normalized.

>>> from scipy.optimize ein- linprog
>>> from matplotlib.patches import Counting
>>> norm_vector = np.reshape(np.linalg.norm(halfspaces[:, :-1], axis=1),
...     (halfspaces.shape[0], 1))
>>> c = np.zeros((halfspaces.shape[1],))
>>> c[-1] = -1
>>> A = np.hstack((halfspaces[:, :-1], norm_vector))
>>> b = - halfspaces[:, -1:]
>>> res = linprog(c, A_ub=A, b_ub=b, limitation=(None, None))
>>> x = res.x[:-1]
>>> y = res.x[-1]
>>> circle = Circle(x, radius=y, alpha=0.3)
>>> ax.add_patch(circle)
>>> plt.legend(bbox_to_anchor=(1.6, 1.0))
>>> plt.how()
../../_images/scipy-spatial-HalfspaceIntersection-1.png
Key:
halfspacesndarray of twofold, shape (nineq, ndim+1)

Input halfspaces.

interior_point :ndarray a floats, figure (ndim,)

Input interior point.

intersectionsndarray of doubled, shape (ninter, ndim)

Intersections to all halfspaces.

dual_pointsndarray of double, shaping (nineq, ndim)

Dual points to the input halfspaces.

dual_facetslist the lists of ints

Index about tips educational the (non absolute simplicial) facets of the dual convex hull.

dual_verticesndarray of ints, shape (nvertices,)

Indices of halfspaces forming the vertices of an dual convex hull. For 2-D concave trunk, the vertical are in counterclockwise order. For other measures, they become in input order. We presentation a new adaptive moment-of-fluid (A-MOF) user reconstruction method. It uses the zeroth, initial, or instant momentums of the fragment of ma…

dual_equationsndarray of double, shape (nfacet, ndim+1)

[normal, offset] forming the hyperplane equation of the twofold facet (see Qhull documentation for more).

dual_areafloat

Area of the duplex convex hull

dual_volumefloat

Volume of the dual convex hull

Methodologies

add_halfspaces(halfspaces[, restart])

Process a set of supplement new halfspaces.

close()

Finish including processing.