ben*_*ten 5 python delaunay spatial scipy convex-hull
我有一组点,想找到凸壳.当我把它们交给scipy.spatial(ConvexHull或Delaunay)时,我只能得到原来的一组点.通过施工,情况不应该如此.
以下是作为酸洗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()
Run Code Online (Sandbox Code Playgroud)
显然有些这些点是内部的凸包,并应通过spatial.ConvexHull(点)或spatial.Delaunay(点)被移除,如在给定的2D例子完成这里.
有谁知道为什么我得到了原来的一套积分?我可以蛮力找到外部点并仅绘制那些(最终目标是由点近似的外部形状的表面图),但似乎scipy.spatial应该能够做到这一点.
您使用的.points属性可以返回输入点.尝试使用该.simplices属性,这将为您提供"形成凸包的简单方面的点".