gpt4 book ai didi

python - scipy.spatial 中的凸包例程让我恢复了原来的点集

转载 作者:太空狗 更新时间:2023-10-30 00:56:19 25 4
gpt4 key购买 nike

我有一组点,想找到凸包。当我将它们交给 scipy.spatial(ConvexHull 或 Delaunay)时,我只是得到了原始的点集。按照结构,这不应该是这种情况。

这是 the points作为腌制的 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) 删除,如给出的二维示例中所做的那样 here .

有谁知道我为什么要找回原来的积分集?我可以蛮力找到外部点并仅绘制那些(最终目标是由点近似的外部形状的表面图),但似乎 scipy.spatial 应该能够做到这一点。

最佳答案

您正在使用 .points 属性返回输入点。尝试改用 .simplices 属性,它为您提供“形成凸包的简单面的点”。

See the documentation for more info.

关于python - scipy.spatial 中的凸包例程让我恢复了原来的点集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19391811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com