Implemented function: lloyd_relax() | Method key: "poisson_disk_relaxed"
The Bridson Poisson disk algorithm produces a distribution that satisfies the hard exclusion constraint (d_{ij} ≥ h), but the resulting node set is not as uniform as possible: large empty regions and irregular inter-node distances are common, especially for small k values. This non-uniformity can lead to:
Lloyd's algorithm (Lloyd 1982, also known as k-means smoothing or centroidal Voronoi tessellation optimization) is an iterative post-processing technique that improves node uniformity by repeatedly moving each interior node toward the centroid of its Voronoi cell. Applied to a Poisson disk point set, it produces a centroidal Voronoi tessellation (CVT) — a distribution where each node is the centroid of its own Voronoi cell, which is provably the most uniform node arrangement for a given number of points.
The lloyd_relax() function implements a simplified, computationally efficient variant: instead of computing Voronoi cells explicitly, it uses the Delaunay neighbours of each interior node as a proxy for the Voronoi cell vertices, and moves the node toward the centroid of its Delaunay neighbours (Laplacian smoothing). This approximation is much faster than full CVT optimization while still significantly improving node uniformity.
Let I = {x1, …, xNint} be the set of interior node positions, and B be the set of (fixed) boundary nodes. The Delaunay triangulation T is computed on all nodes.
At each iteration t, each interior node xi is updated by:
where:
Boundary nodes are held fixed throughout the iteration. The Delaunay triangulation is recomputed at each iteration to account for the updated node positions.
The iteration stops when either:
For planar (2D) clouds, the algorithm projects the 3D node positions onto the dominant 2D plane (by discarding the axis with minimum variance) before computing the Delaunay triangulation. This ensures numerical stability and correct connectivity even when the plane is not aligned with the coordinate axes.
scipy.spatial.Delaunay.Delaunay.vertex_neighbor_vertices (CSR connectivity), avoiding Python-side adjacency rebuilds.entity object (the CAD entity being generated), the function activates an in-loop geometry containment constraint (see Section 4.1) to prevent nodes from drifting outside the valid geometric domain during iteration.Laplacian smoothing moves each interior node toward the centroid of its Delaunay neighbours. For nodes near hole edges or the outer boundary, this displacement may be directed toward — or even through — a geometric boundary, causing the node to end up inside a hole or outside the outer perimeter. The magnitude of the drift is typically ω · δ per iteration, where δ is the distance to the centroid, but in thin regions (narrow material strips between holes) it is possible for nodes to cross a hole boundary in a single step.
GearMaster uses a two-layer strategy to handle geometry containment robustly: an in-loop step-rejection constraint (active during iteration) and a post-relaxation cleanup filter (applied once after all iterations complete).
When lloyd_relax() is called with an entity argument, the function builds a set of geometry constraints from the CAD shape before entering the iteration loop. Each constraint encodes the 2D boundary polygon and hole polygons of one planar face of the entity, expressed in that face's local 2D coordinate frame.
At each iteration, after computing the displacement step si = ω · (¯xi − xi) for each interior node, the tentative new position
is projected into the 2D frame of each matching face and checked against the face's boundary polygon and holes using contains_points_with_holes(). If the tentative position is not contained in any valid face region, the step is rejected:
The node simply remains at its current position for that iteration and may be displaced in a future iteration if the Delaunay connectivity changes.
This constraint is the primary mechanism that prevents nodes from accumulating in invalid regions over multiple iterations. Without it, even a modest number of iterations (5–10) can push a significant fraction of boundary-adjacent interior nodes into holes in geometries with thin material strips between holes.
_filter_post_relax)
After lloyd_relax() completes all iterations, the PointCloudGenerator applies a final containment filter (_filter_post_relax). The filter:
matplotlib.path.Path.contains_points() (ray casting).entity passed), the post-relax filter is the sole containment mechanism and may need to remove a larger number of drifted nodes.
n_iter (int, default 10): Maximum number of smoothing iterations.tol (float, default 1e-4): Convergence tolerance on maximum node displacement [model units].omega (float, default 0.5): Relaxation factor in (0, 1]. Lower values give more conservative, stable smoothing.
When using interior_method="poisson_disk_relaxed", these parameters are applied at fixed default values. The n_relax_iter parameter of PointCloudGenerator controls the maximum number of iterations.
Use "poisson_disk_relaxed" when improved node uniformity is desired over the raw Bridson output, without the overhead of a full Delaunay-based mesher. Typical use cases: