Bounded Voronoi diagram from 2D pointsĀ¶
Let us create some points and compute the Voronoi diagram (aka Thiessen polygons or Dirichlet tesselation). The Voronoi diagram is bounded by the buffered convex hull of the given points. The buffer size needs to be specified.
Then we can plot the Voronoi diagram. Optional we can display the points respectively the center of Voronoi cells and the triangulation of the points.
InĀ [1]:
Copied!
%matplotlib inline
from voromesh import Voronoi
from numpy import array
points = array([[-0.5, -0.5], [0.5, -0.5],
[-0.5, 0.5], [0.5, 0.5],
[0.0, 0.0]])
voro = Voronoi(points, buffer_size=0.4)
voro.plot(center=True, tri=True)
%matplotlib inline
from voromesh import Voronoi
from numpy import array
points = array([[-0.5, -0.5], [0.5, -0.5],
[-0.5, 0.5], [0.5, 0.5],
[0.0, 0.0]])
voro = Voronoi(points, buffer_size=0.4)
voro.plot(center=True, tri=True)
Matplotlib is building the font cache; this may take a moment.
As next step we export the Voronoi diagramm as Pyvista unstructured grid for further usage.
InĀ [2]:
Copied!
import pyvista as pv
mesh = voro.to_pyvista()
# Plot the grid in notebook
pv.set_jupyter_backend('static')
mesh.plot(notebook=True, show_edges=True)
# mesh.save("voronoi.vtu")
import pyvista as pv
mesh = voro.to_pyvista()
# Plot the grid in notebook
pv.set_jupyter_backend('static')
mesh.plot(notebook=True, show_edges=True)
# mesh.save("voronoi.vtu")