Scipy ConvexHull 和 QHull:rank/dimension 不是最大的

Scipy ConvexHull and QHull: rank/dimension is not maximal

我正在尝试使用库 Scipy 和 ConvexHull 创建一个 Convex Hull。据我所知,它调用QHull。

当我要添加的点没有'full dimension'时出现问题。示例:

from scipy.spatial import ConvexHull
import numpy as np
points = np.append([[0,2]],[[2,0]],axis=0)
hull = ConvexHull(points)

具有输出:

Traceback (most recent call last):
  File "C:/folder/vertices_scipy2.py", line 5, in <module>
hull = ConvexHull(points)
  File "scipy\spatial\qhull.pyx", line 2230, in scipy.spatial.qhull.ConvexHull.__init__ (scipy\spatial\qhull.c:20317)
  File "scipy\spatial\qhull.pyx", line 328, in scipy.spatial.qhull._Qhull.__init__ (scipy\spatial\qhull.c:3639)
QhullError: Qhull error

但是,如果我添加一个额外的点,使凸包具有完整的维度:

from scipy.spatial import ConvexHull
import numpy as np
points = np.append([[0,0],[0,2]],[[2,0]],axis=0)
hull = ConvexHull(points)

然后一切正常。一个例子和另一个例子的区别(我做过很多其他的例子,所以我很确定)是第一种情况下的凸包在2维space中是1维的,而在第二种情况下, 是 2-dimensional in 2-dimensional space (即全维).

有什么想法吗?我想传递一些 qhull_options 因为 docs 表明,正如答案中提到的那样:

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

然而,我已经阅读了很多 options in QHull 和 none 似乎解决了这个问题。我随机尝试了其中一些,但收效甚微。

任何帮助都会有所帮助。我正在开发一个程序来创建数百个这样的外壳,其中一些不是全尺寸的。

ConvexHull好像不支持退化凸包

点数必须至少为维数加一才能具有非退化凸包。

例如在一个平面上,你需要 3 个点才能有一个非退化包:3 个点的凸包将是一个三角形,而退化包将是 2 个点之间的线段。

事实上 docs 提到:

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

我无法发表评论,所以这不是真正的答案,但您可以通过以下方式获得更好的错误描述:

>>> points2 = np.append([[0,0],[1,1]],[[2,2]],axis=0)
>>> hull = ConvexHull(points2)
QH6154 qhull precision error: initial facet 1 is coplanar with the interior point
ERRONEOUS FACET:
- f1
    - flags: bottom simplicial flipped
    - normal:   -0.7071   0.7071
    - offset:         -0
    - vertices: p2(v1) p0(v0)
    - neighboring facets: f2 f3

While executing:  | qhull i Qt
Options selected for Qhull 2012.1 2012/02/18:
  run-id 972186139  incidence  Qtriangulate  _pre-merge  _zero-centrum
  _max-width  2  Error-roundoff 1.7e-15  _one-merge 8.6e-15
  _near-inside 4.3e-14  Visible-distance 3.4e-15  U-coplanar-distance 3.4e-15
  Width-outside 6.9e-15  _wide-facet 2.1e-14

The input to qhull appears to be less than 2 dimensional, or a
computation has overflowed.

Qhull could not construct a clearly convex simplex from points:
- p1(v2):     1     1
- p2(v1):     2     2
- p0(v0):     0     0

The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet.  The maximum round off error for
computing distances is 1.7e-15.  The center point, facets and distances
to the center point are as follows:

center point        1        1

facet p2 p0 distance=    0
facet p1 p0 distance=    0
facet p1 p2 distance=    0

These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates.  Trial points
are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are:
  0:         0         2  difference=    2
  1:         0         2  difference=    2

If the input should be full dimensional, you have several options that
may determine an initial simplex:
  - use 'QJ'  to joggle the input and make it full dimensional
  - use 'QbB' to scale the points to the unit cube
  - use 'QR0' to randomly rotate the input for different maximum points
  - use 'Qs'  to search all points for the initial simplex
  - use 'En'  to specify a maximum roundoff error less than 1.7e-15.
  - trace execution with 'T3' to see the determinant for each point.

If the input is lower dimensional:
  - use 'QJ' to joggle the input and make it full dimensional
  - use 'Qbk:0Bk:0' to delete coordinate k from the input.  You should
    pick the coordinate with the least range.  The hull will have the
    correct topology.
  - determine the flat containing the points, rotate the points
    into a coordinate plane, and delete the other coordinates.
  - add one or more points to make the input full dimensional.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "qhull.pyx", line 2230, in scipy.spatial.qhull.ConvexHull.__init__ (scipy/spatial/qhull.c:19173)
  File "qhull.pyx", line 328, in scipy.spatial.qhull._Qhull.__init__ (scipy/spatial/qhull.c:3670)
scipy.spatial.qhull.QhullError: Qhull error
>>>