Voronoi Diagrams

Based on code from Joseph O’Rourke.

Voronoi Diagram from a set of points

Generate some 2D points with coords in [-1, 1]:

npts=30;
pts=RandomReal[{-1,1},{npts,2}];

Create a “mesh region” for the Voronoi diagram:

meshVD=VoronoiMesh[pts];

Draw the Voronoi diagram:

Show[{
HighlightMesh[meshVD,{Style[0,Blue],Style[1,Purple],Style[2,LightCyan]}],
Graphics[{PointSize[Medium],Orange,Point[pts]}]
}]

Interactive Voronoi Diagram

The following code produces an interactive Voronoi Diagram: you can move the points and see how the Voronoi cells change. ⌘-click or Alt-click to add or delete points.

npts=10;
Manipulate[
HighlightMesh[VoronoiMesh[pts],{Style[0,Blue],Style[1,Purple],Style[2,LightCyan]}],
{{pts,RandomReal[{-1,1},{npts,2}]},Locator,LocatorAutoCreate->{2,∞}}
]