environmentaltools.spatial.bounded_voronoi
- environmentaltools.spatial.bounded_voronoi(towers, bounding_box)[source]
Generate bounded Voronoi diagram with finite regions.
Creates a Voronoi diagram constrained to a rectangular bounding box by mirroring edge points outside the box. This ensures all Voronoi regions within the box are finite and bounded.
- Parameters:
towers (np.ndarray) – Generator points as (N, 2) array of [x, y] coordinates
bounding_box (tuple or list) – Rectangular bounds as [xmin, xmax, ymin, ymax]
- Returns:
Voronoi diagram object with additional attributes: - filtered_points: generator points within bounding box - filtered_regions: list of region vertex indices for points in box
- Return type:
scipy.spatial.Voronoi
Notes
The algorithm mirrors points across each boundary (left, right, top, bottom) to create “virtual” points outside the box. This forces edge Voronoi cells to close at the boundaries rather than extending to infinity.
Only the first 1/5 of regions (corresponding to original points) are retained in filtered_regions, as the remaining regions belong to mirrored points.
Examples
>>> import numpy as np >>> points = np.array([[25, 25], [75, 25], [50, 75]]) >>> vor = bounded_voronoi(points, [0, 100, 0, 100]) >>> print(f"Number of filtered regions: {len(vor.filtered_regions)}")