scipy.spatial.

Voronoi#

class scipy.spatial.Voronoi(points, furthest_site=False, incremental=False, qhull_options=None)#

N 維空間中的 Voronoi 圖。

版本 0.12.0 新增。

參數:
pointsndarray of floats, shape (npoints, ndim)

用於建構 Voronoi 圖的點座標

furthest_sitebool, optional

是否計算最遠點 Voronoi 圖。預設值:False

incrementalbool, optional

允許增量新增點。這會佔用一些額外資源。

qhull_optionsstr, optional

傳遞給 Qhull 的其他選項。詳情請參閱 Qhull 手冊。(預設值:ndim > 4 時為 “Qbb Qc Qz Qx”,否則為 “Qbb Qc Qz”。增量模式省略 “Qz”。)

引發:
QhullError

當 Qhull 遇到錯誤情況時引發,例如幾何退化,且未啟用解決方案選項。

ValueError

如果給定的輸入陣列不相容則引發。

註解

Voronoi 圖是使用 Qhull 函式庫 計算的。

範例

點集合的 Voronoi 圖

>>> import numpy as np
>>> 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()
../../_images/scipy-spatial-Voronoi-1_00_00.png

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)
屬性:
pointsndarray of double, shape (npoints, ndim)

輸入點的座標。

verticesndarray of double, shape (nvertices, ndim)

Voronoi 頂點的座標。

ridge_pointsndarray of ints, shape (nridges, 2)

每個 Voronoi 脊所在的點的索引。

ridge_verticeslist of list of ints, shape (nridges, *)

構成每個 Voronoi 脊的 Voronoi 頂點的索引。

regionslist of list of ints, shape (nregions, *)

構成每個 Voronoi 區域的 Voronoi 頂點的索引。 -1 表示 Voronoi 圖外部的頂點。 當指定 qhull 選項 “Qz” 時,空的子列表表示內部新增的無限遠點的 Voronoi 區域。

point_regionarray of ints, shape (npoints)

每個輸入點的 Voronoi 區域的索引。 如果未指定 qhull 選項 “Qc”,則對於未與 Voronoi 區域關聯的點,列表將包含 -1。 如果指定了 qhull 選項 “Qz”,則區域數量將比元素數量少一個,因為內部會新增一個無限遠點以方便計算。

furthest_site

如果這是最遠點三角剖分則為 True,否則為 False。

版本 1.4.0 新增。

方法

add_points(points[, restart])

處理一組額外的新點。

close()

完成增量處理。