Concept Flow - Voronoi diagrams
Input points
Compute Voronoi
Find edges and vertices
Plot Voronoi cells
Visualize regions
Start with points, compute Voronoi regions dividing space, then plot edges and vertices to visualize.
from scipy.spatial import Voronoi, voronoi_plot_2d import matplotlib.pyplot as plt points = [[1,1], [2,3], [3,1], [5,4]] vor = Voronoi(points) voronoi_plot_2d(vor) plt.show()
| Step | Action | Input | Output | Notes |
|---|---|---|---|---|
| 1 | Input points | [[1,1],[2,3],[3,1],[5,4]] | Points array | Points to build Voronoi from |
| 2 | Compute Voronoi | Points array | Voronoi object | Calculates edges, vertices, regions |
| 3 | Extract vertices | Voronoi object | Vertices array | Coordinates of Voronoi vertices |
| 4 | Extract ridge vertices | Voronoi object | Pairs of vertex indices | Edges between vertices |
| 5 | Plot Voronoi | Voronoi object | Plot on matplotlib | Visualizes cells and edges |
| 6 | Show plot | Plot | Window with diagram | Displays Voronoi diagram |
| 7 | End | N/A | N/A | Execution complete |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|
| points | [[1,1],[2,3],[3,1],[5,4]] | [[1,1],[2,3],[3,1],[5,4]] | [[1,1],[2,3],[3,1],[5,4]] | [[1,1],[2,3],[3,1],[5,4]] | [[1,1],[2,3],[3,1],[5,4]] |
| vor | N/A | Voronoi object | Voronoi object | Voronoi object | Voronoi object |
| vertices | N/A | N/A | [array of vertex coords] | [array of vertex coords] | [array of vertex coords] |
| ridge_vertices | N/A | N/A | N/A | [list of vertex index pairs] | [list of vertex index pairs] |
Voronoi diagrams split space by closest points. Use scipy.spatial.Voronoi(points) to compute. Vertices are intersection points of edges. Edges can be finite or infinite (-1 index). Plot with voronoi_plot_2d(vor) and plt.show().