我有一组点并想找到凸包。当我将它们提供给scipy.spatial(无论是ConvexHull还是Delaunay),我只会得到原始点集。按照构造,这不应该是这种情况。
这里是点的pickled numpy数组。下面是我的代码:
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()
显然,这些点中有一些是凸包内部的,应该通过spatial.ConvexHull(points)或spatial.Delaunay(points)进行去除,就像在这里给出的2D示例中所做的那样。
是否有人知道为什么我会得到原始点集?我可以采用暴力方法找到外部点并仅绘制它们(最终目标是对由这些点近似的外部形状进行表面绘制),但是看起来scipy.spatial应该能够完成此任务。
hull.points[np.unique(hull.simplices)]
来获取凸包中实际唯一点的列表。 - Jaimehull.points[hull.vertices]
将按所需顺序提供这些点。 - dnivog