سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top