Eul*_*ter 4 python geometry voronoi numpy scipy
我认为我的问题与这个问题或其他问题有一些共同点,但无论如何,我的问题并不是专门针对它们的。
我想,在找到某些点的 voronoi 镶嵌之后,能够检查其他给定点在镶嵌中的位置。特别是:
假设有 50 个额外点,我希望能够计算每个 voronoi 单元包含多少这些额外点。
我的 MWE
from scipy.spatial import ConvexHull, Voronoi, voronoi_plot_2d
import matplotlib.pyplot as plt
points = [[0,0], [1,4], [2,3], [4,1], [1,1], [2,2], [5,3]]
#voronoi
vor = Voronoi(points)
voronoi_plot_2d(vor)
plt.show()
Run Code Online (Sandbox Code Playgroud)
现在我得到了加分
extraPoints = [[0.5,0.2], [3, 0], [4,0],[5,0], [4,3]]
# In this case we have that the first point is in the bottom left,
# the successive three are in the bottom right and the last one
# is in the top right cell.
Run Code Online (Sandbox Code Playgroud)
我想使用你可以得到vor.regionsor的事实vor.vertices,但是我真的想不出任何东西..
是否有参数或方法可以做到这一点
这个东西很有趣,我已经使用这里的答案为你解决了这个函数的文档在这里
from scipy.spatial import cKDTree
points = [[0,0], [1,4], [2,3], [4,1], [1,1], [2,2], [5,3]]
voronoi_kdtree = cKDTree(points)
extraPoints = [[0.5,0.2], [3, 0], [4,0],[5,0], [4,3]]
test_point_dist, test_point_regions = voronoi_kdtree.query(extraPoints)
test_point_regions
>>> array([0, 3, 3, 3, 6])
Run Code Online (Sandbox Code Playgroud)
这是您解释该数组的方式 - 将调用您的“额外点”测试点。您的第一个测试点 (0.5,0.2) 位于第 0 个点 (0,0) 附近的区域。第二、第三和第四点位于点 3(0-index)附近的区域,即 (4,1)。最后一个测试点在 (5,3) 左右。
我认为想象这些区域是多边形并尝试应用这种算法可能会有问题,因为边缘上的一些区域是无限远的区域。