Voronoi DiagramsΒΆ
scikit-geometry comes with methods to efficiently compute the voronoi diagram of points.
[1]:
import numpy as np
from skgeom import *
from matplotlib import pyplot as plt
[2]:
npoints = np.random.rand(100, 2) * 20 - 10
points = []
for r in npoints:
points.append(Point2(*r))
vdiag = voronoi.VoronoiDiagram()
for p in points:
vdiag.insert(p)
for he in vdiag.edges:
source, target = he.source(), he.target()
if source and target:
plt.plot([source.point().x(), target.point().x()], [source.point().y(), target.point().y()])
plt.scatter(npoints[:, 0], npoints[:, 1])
plt.axis('equal')
plt.gca().set_adjustable("box")
plt.gca().set_xlim([-10, 10])
plt.gca().set_ylim([-10, 10])
plt.show()