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

时间:2018-12-04 15:13:30

标签: python scipy voronoi scipy-spatial

我正在使用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 diagram

如何获取橙色点的坐标?似乎没有(至少有文献记载)该属性。

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

1 个答案:

答案 0 :(得分:1)

这些点在vertices属性中可用。 documentation of Voronoivertices属性描述为“ Voronoi顶点的坐标”。 (在链接的网页中向下滚动以找到属性的描述。)

这是您的示例:

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)

plot