Standard Voronoi Diagram¶

Python Script¶

The basename for this file is `standard_voronoi.py`. The file can be run using this command:

```microstructpy --demo=standard_voronoi.py
```

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)])
seeds.position(domain)

# 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')

plt.axis('square')
plt.xlim(domain.limits[0])
plt.ylim(domain.limits[1])

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):
os.makedirs(dirs)
```

Domain¶

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

Seeds¶

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.

Plotting¶

The output Voronoi diagram is plotted in Fig. 20.