scipy.spatial.Voronoi¶
- class scipy.spatial.Voronoi(points, furthest_site=False, incremental=False, qhull_options=None)¶
N维的Voronoi图。
0.12.0 新版功能.
- 参数
- points浮点数,形状(npoint,ndim)
用于构建Voronoi图的点的坐标
- furthest_site布尔值,可选
是否计算最远位置的Voronoi图。默认值:False
- incremental布尔值,可选
允许增量添加新点。这会占用一些额外的资源。
- qhull_options字符串,可选
要传递给Qhull的其他选项。有关详细信息,请参阅Qhull手册。(默认值:ndim>4时为“qbb qc qz qx”,否则为“qbb qc qz”。增量模式省略了“qz”。)
- 加薪
- QhullError
当Qhull遇到错误条件时引发,例如未启用要解决的选项时的几何退化。
- ValueError
如果将不兼容的数组作为输入给定,则引发。
注意事项
Voronoi图是使用 Qhull library 。
示例
一组点的Voronoi图:
>>> points = np.array([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], ... [2, 0], [2, 1], [2, 2]]) >>> from scipy.spatial import Voronoi, voronoi_plot_2d >>> vor = Voronoi(points)
绘制它:
>>> import matplotlib.pyplot as plt >>> fig = voronoi_plot_2d(vor) >>> plt.show()
Voronoi顶点:
>>> vor.vertices array([[0.5, 0.5], [0.5, 1.5], [1.5, 0.5], [1.5, 1.5]])
有一个有限的Voronoi区域和四个有限的Voronoi脊:
>>> vor.regions [[], [-1, 0], [-1, 1], [1, -1, 0], [3, -1, 2], [-1, 3], [-1, 2], [0, 1, 3, 2], [2, -1, 0], [3, -1, 1]] >>> vor.ridge_vertices [[-1, 0], [-1, 0], [-1, 1], [-1, 1], [0, 1], [-1, 3], [-1, 2], [2, 3], [-1, 3], [-1, 2], [1, 3], [0, 2]]
在以下输入点之间绘制的直线之间的山脊是垂直的:
>>> vor.ridge_points array([[0, 3], [0, 1], [2, 5], [2, 1], [1, 4], [7, 8], [7, 6], [7, 4], [8, 5], [6, 3], [4, 5], [4, 3]], dtype=int32)
- 属性
- points双倍形状的ndarray(npoints,ndim)
输入点的坐标。
- vertices双倍形状的ndarray(nverts,ndim)
Voronoi顶点的坐标。
- ridge_points :ndarray of Ints,Shape
(nridges, 2)
整数的ndarray,形状 每个Voronoi山脊之间的点的索引。
- ridge_vertices :整数列表,形状
(nridges, *)
整数列表,形状 形成每个Voronoi脊的Voronoi顶点的索引。
- 区域 :整数列表,形状
(nregions, *)
整数列表,形状 形成每个Voronoi区域的Voronoi顶点的索引。-1表示Voronoi图外部的顶点。
- point_region整数列表,形状(点)
每个输入点的Voronoi区域的索引。如果未指定qhull选项“qc”,则列表将包含不与Voronoi区域关联的点的-1。
- furthest_site
如果这是最远的场地三角测量,则为True,否则为False。
1.4.0 新版功能.
方法:
add_points
\(积分[, restart] )处理一组附加的新点。
close
\()完成增量处理。