最近需要用到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)
>>>vor.vertices
array([[0.5, 0.5],
[1.5, 0.5],
[0.5, 1.5].
[1.5, 1.5]])
>>> 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