在scipy.spatial中使用凸包例程返回了我最初的点集

7

我有一组点并想找到凸包。当我将它们提供给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应该能够完成此任务。

1个回答

9
你正在使用.points属性,该属性会返回输入点。尝试使用.simplices属性,该属性返回"构成凸包的单纯面的点"。请查看文档获取更多信息。

4
他可能想调用 hull.points[np.unique(hull.simplices)] 来获取凸包中实际唯一点的列表。 - Jaime
搞定了!非常感谢。 - benten
1
如果您正在寻找创建多边形几何图形的点,则 hull.points[hull.vertices] 将按所需顺序提供这些点。 - dnivog

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接