python中集成的Voronoi包

最近需要用到Voronoi Graph进行模拟实验,因此总结下python中Voronoi包中的相关参数;

1、首先引入相应的包

from scipy.spatial import Voronoi
from scipy.spatial import KDTree

import numpy as np

2、生成Voronoi Graph

points  = np.array([[0, 0],[0, 1],[0, 2],
                    [1, 0],[1, 1],[1, 2],
                    [2, 0],[2, 1],[2, 2]])
vor = Voronoi(points)

生成的Graph

>>>vor.vertices
   array([[0.5, 0.5],
          [1.5, 0.5],
          [0.5, 1.5].
          [1.5, 1.5]])

vertices

>>> vor.regions        // Indices of the *Voronoi vertices* forming each Voronoi region. 
                       //-1 indicates vertex outside the Voronoi diagram.

[[],
 [-1, 0],
 [-1, 1], 
 [1, -1, 0],
 [3, -1, 2],
 [-1, 3], 
 [-1, 2],
 [3, 2, 0, 1], 
 [3, -1, 0],
 [3, -1, 1]]

>>> vor.ridge_vertices     // 12条
                          //Indices of the Voronoi vertices forming each Voronoi ridge.

>>> vor.ridge_points      //Indices of the points between which each Voronoi ridge lies.

3、查询任何一个点落在哪个region

tree = KDtree(points)
>>> tree.query([0.1, 0.1])       //哪个点距离这个点最近
    (0.14142135623730953, 0)

因此在region 0
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值