首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在voronoi_finite_polygons_2d函数中获得与给定点相关联的区域?

如何在voronoi_finite_polygons_2d函数中获得与给定点相关联的区域?
EN

Stack Overflow用户
提问于 2019-05-21 17:11:52
回答 1查看 485关注 0票数 2

我正在尝试修改我在stackoverflow上找到的this code,以创建一个具有有限边界的voronoi。

然而,我的问题是,我不知道如何将区域与给定点相关联。这是用point_region方法在普通的Voronoi中完成的,但在这里不起作用,因为区域发生了变化。

我使用的数据点是:

代码语言:javascript
复制
points = array([[289255.176  , 921667.461  ],
       [289296.31699, 921687.13826],
       [289463.30305, 921770.12504],
       [289725.08002, 921905.75745],
       [289960.48198, 922099.46056],
       [290106.98928, 922361.79529],
       [289255.184  , 921646.244  ],
       [289307.48677, 921627.05485],
       [289500.80493, 921555.50067],
       [289825.14532, 921435.65147],
       [290141.79326, 921322.77935],
       [290454.91721, 921211.09355],
       [289255.187  , 921635.627  ],
       [289327.07776, 921558.85263],
       [289565.21795, 921298.17707],
       [289875.40176, 920978.013  ],
       [290192.86361, 920656.82017],
       [289255.185  , 921630.386  ],
       [289318.54181, 921453.18492],
       [289421.06861, 921167.57934],
       [289565.42462, 920770.1386 ],
       [289701.83141, 920376.28627],
       [289833.6501 , 919990.66467]])

vor = Voronoi(points)

min_x = vor.min_bound[0] - 100
max_x = vor.max_bound[0] + 100
min_y = vor.min_bound[1] - 100
max_y = vor.max_bound[1] + 100

regions, vertices, pts = voronoi_finite_polygons_2d(vor)
EN

回答 1

Stack Overflow用户

发布于 2019-06-28 07:53:51

此代码使用多边形分析中的点为您提供与给定的有限 Voronoi区域相关联的点。让我们假设我们希望找到哪个点与vor_regions列表中的第二个Voronoi区域相关联。

代码语言:javascript
复制
vor = Voronoi(points)
vor_regions = vor.regions
vor_vertices = vor.vertices

from shapely.geometry import MultiPoint
from shapely.geometry import Point

region = vor_regions[1]   
coords = tuple(map(tuple, vor_vertices[region]))
poly = MultiPoint(coords).convex_hull
for i in range(0,len(points)):
    pt = Point(tuple(map(tuple, points[i:i+1])))
    if poly.contains(pt) == True:
        print('The input region is ')
        print(region)
        print('Index of the associated point in the vor_vertices list is '+str(i))
        print('The coordinates of the associated point is ')
        print(pt)

输出:

代码语言:javascript
复制
The input region is 
[6, 2, 1, 0, 5]
Index of the associated point in the vor_vertices list is 4
The coordinates of the associated point is 
POINT (289960.48198 922099.46056)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56234965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档