Standard Voronoi Diagram

Python Script

The basename for this file is The file can be run using this command:


The full text of the script is:

import os

from matplotlib import pyplot as plt

import microstructpy as msp

# Create domain
domain = msp.geometry.Square()

# Create list of seed points
factory = msp.seeding.Seed.factory
n = 50
seeds = msp.seeding.SeedList([factory('circle', r=0.01) for i in range(n)])

# Create Voronoi diagram
pmesh = msp.meshing.PolyMesh.from_seeds(seeds, domain)

# Plot Voronoi diagram and seed points
pmesh.plot(edgecolors='k', facecolors='gray')
seeds.plot(edgecolors='k', facecolors='none')


file_dir = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(file_dir, 'standard_voronoi/voronoi_diagram.png')
dirs = os.path.dirname(filename)
if not os.path.exists(dirs):
plt.savefig(filename, bbox_inches='tight', pad_inches=0)


The domain of the microstructure is a Square. Without arguments, the square’s center is (0, 0) and side length is 1.


A set of 50 seed circles with small radius is initially created. Calling the position() method positions the points according to random uniform distributions in the domain.

Polygon Mesh

A polygon mesh is created from the list of seed points using the from_seeds() class method. The mesh is plotted and saved into a PNG file in the remaining lines of the script.


The output Voronoi diagram is plotted in Fig. 20.


Fig. 20 Standard Voronoi diagram.