我正在使用一种算法,对于每次迭代,需要找到一组生态协调所属的Voronoi图的哪个区域.也就是说,每个坐标位于哪个区域内.(我们可以假设所有坐标都属于一个区域,如果这有任何区别的话.)
我还没有任何适用于Python的代码,但伪代码看起来像这样:
## we are in two dimensions and we have 0<x<1, 0<y<1.
for i in xrange(1000):
XY = get_random_points_in_domain()
XY_candidates = get_random_points_in_domain()
vor = Voronoi(XY) # for instance scipy.spatial.Voronoi
regions = get_regions_of_candidates(vor,XY_candidates) # this is the function i need
## use regions for something
Run Code Online (Sandbox Code Playgroud)
我知道scipy.Delaunay有一个名为find_simplex的函数,它会在Delaunay三角剖分中完成我想要的简单操作,但是我需要Voronoi图,并且我希望避免构建它们.
问题:
1.是否有某种类型的库可以让我轻松完成这项工作?
2.如果没有,是否有一个好的算法可以让我有效地做到这一点?
更新
Jamie的解决方案正是我想要的.我有点尴尬,虽然我自己也没想过......