如何从 scipy.spatial.Voronoi 获取边界交汇点的坐标

How to get coordinates of border meeting points from scipy.spatial.Voronoi

我正在使用 scipy.spatial.Voronoi 计算 Voronoi 图:

import numpy as np
from scipy.spatial import Voronoi

points = np.array([[51.129378, 17.02925 ],
                   [51.086225, 17.012689],
                   [50.913433, 15.765608],
                   [53.121764, 17.987906],
                   [53.134083, 17.995708],
                   [51.75805 , 19.529786]])


vor = Voronoi(points)

我收到了下图:

如何获取橙色点的坐标?似乎没有(至少有文档)它的属性。

动机:我的目标是计算没有蓝点的最大圆。所以我打算计算每个橙色点和蓝色点之间的距离。然后我将检查每个橙色点并选择一个具有最高最小距离值的点。它将成为我目标圈的中心。也许没有 Voronoi 有其他方法可以做到这一点?

这些点在 vertices 属性中可用。 documentation of Voronoivertices 属性描述为 "Coordinates of the Voronoi vertices."(在链接的网页中向下滚动以查找属性的描述。)

这是你的例子:

In [5]: import numpy as np

In [6]: from scipy.spatial import Voronoi

In [7]: points = np.array([[51.129378, 17.02925 ],
   ...:                    [51.086225, 17.012689],
   ...:                    [50.913433, 15.765608],
   ...:                    [53.121764, 17.987906],
   ...:                    [53.134083, 17.995708],
   ...:                    [51.75805 , 19.529786]])
   ...:                    

In [8]: vor = Voronoi(points)

这些是绘制为橙色点的点:

In [9]: vor.vertices
Out[9]: 
array([[52.56952748, 18.87348869],
       [51.7974129 , 18.19059283],
       [56.91850562, 12.00665177],
       [52.80703622, 16.09228084],
       [50.53735155, 18.50739102],
       [51.36995954, 16.33786426]])

请注意,voronoi_plot_2d(vor) 在图上选择的 x 和 y 限制太小而无法看到所有顶点。这是显示所有内容的图:

In [15]: import matplotlib.pyplot as plt

In [16]: from scipy.spatial import voronoi_plot_2d

In [17]: voronoi_plot_2d(vor)
Out[17]: <Figure size 1280x960 with 1 Axes>

In [18]: plt.xlim(50, 58)
Out[18]: (50, 58)

In [19]: plt.ylim(11, 20)
Out[19]: (11, 20)