Convex hull routines in scipy.spatial gives me back my original set of points
Asked Answered
T

1

7

I have a set of points and want to find the convex hull. When I give them to scipy.spatial (either ConvexHull or Delaunay), I just get the original set of points back. By construction, this should not be the case.

Here are the points as a pickled numpy array. My code is given below:

import pickle
from scipy import spatial
import matplotlib.pyplot as plt

points = pickle.load( open( "points.p", "rb" ) )

hullpoints = spatial.ConvexHull(points).points


# plot points
fig = plt.figure()
ax = fig.gca(projection='3d')
# ax.plot(points[:, 0], points[:, 1], points[:, 2], 'r.') # original points
ax.plot(hullpoints[:, 0], hullpoints[:, 1], hullpoints[:, 2], 'r.') # convex hull of points


# set labels and show()
ax.set_xlabel('Player 1')
ax.set_ylabel('Player 2')
ax.set_zlabel('Player 3')
plt.show()

Obviously some of these points are interior to the convex hull and should be removed via spatial.ConvexHull(points) or spatial.Delaunay(points), as done in the 2d examples given here.

Does anyone know why I'm getting the original set of points back? I could brute-force find the exterior points and plot only those (ultimate goal is a surface plot for exterior shape approximated by the points), but it seems that scipy.spatial should be able to do this.

Tobacco answered 15/10, 2013 at 21:55 Comment(0)
M
9

Your are using the .points attribute which gives you back the input points. Try to use the .simplices attribute instead, which gives you the "points forming the simplical facets of the convex hull".

See the documentation for more info.

Mimosa answered 15/10, 2013 at 22:1 Comment(3)
It's probably hull.points[np.unique(hull.simplices)] that he wants to call to get the actual list of unique points in the convex hull.Massasoit
That does it! Thanks so much.Tobacco
If you are looking for points to create a polygon geometry then hull.points[hull.vertices] will give you the points in the desired sequence.Tolmach

© 2022 - 2024 — McMap. All rights reserved.