pythonnumpyconvex-hullconvex-polygonqhull

Scipy ConvexHull and QHull: rank/dimension is not maximal


I am trying to create a Convex Hull using the library Scipy and ConvexHull. As far as I know, it calls QHull.

The problem appears when the points I want to add do not have 'full dimension'. Example:

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

Has for output:

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

However, if I add an extra points, so that the convex hull has full dimension:

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

then everything works. The difference between one example and the other (I have done many other examples, so that I am certain) is that the convex hull in the first case is 1-dimensional in 2-dimensional space, while in the second one, is 2-dimensional in 2-dimensional space (i.e. full dimensional).

Any ideas? I thought passing some qhull_options since the docs indicate, as it has been mentioned on the answers that:

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

however, I have read many of the options in QHull and none of them seem to address this problem. I have tried some of them at random, with little success.

Any help would be helpful. I am working on a program that creates hundreds of these hulls and some of them are not full-dimensional.


Solution

  • It seems that ConvexHull does not support degenerate convex hulls.

    The number of points must be at least the number of dimensions plus one to have a non-degenerate convex-hull.

    For example in a plane, you need 3 points in order to have a non-degenerate hull: the convex hull for 3 points would be a triangle, while the degenerate hull would be the segment between 2 points.

    in fact the docs mention that:

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