# [SciPy-User] ConvexHull: difficult to get vertices

hayne@sympati... hayne@sympati...
Sun Apr 28 14:09:32 CDT 2013

I am trying to use scipy.spatial.ConvexHull (introduced in scipy 0.12.0) to get the convex polygon surrounding a given polygon (2D).
But there doesn't seem to be any easy way to get the vertices of the convex hull from the result returned from the scipy.spatial.ConvexHull function.
Perhaps (probably?) this is a documentation problem.
The documentation says that it returns an object with attributes: points, simplices, …
The 'points' attribute is supposed to be "Points in the convex hull". But empirically, it has all of the points that were sent as input to the function - not just the points that are in the convex hull.
The 'simplices' attribute has "Indices of points forming the simplical facets of the convex hull". In the case of my 2D polygon, these seem to be the indices of pairs of points forming the line segments of the polygon I want. But they aren't in any particular order (as far as I can see).

I have found that I can get the indices of the points that form the convex polygon that I want by doing the following:

h = scipy.spatial.ConvexHull(polygonVerts)
indices = np.unique(h.simplices.flatten())

And hence the vertices of the convex polygon can be obtained as:

convexPolygonVerts = [polygonVerts[i] for i in indices]

But this seems rather more difficult than it should be.
And this wouldn't work if I had a collection of points in 2D (instead of a polygon) and wanted the bounding polygon.

--
Cameron Hayne
macdev@hayne.net