Poisson Disk Sampling
Understanding Poisson Disk Sampling
In 2024, a group of nine mathematicians produced a staggering, nearly 1,000-page proof regarding the geometric Langlands conjecture. It stands as a peak of pure mathematics—a work so complex that I've accepted I will likely never grasp the proof, or even the initial statements being proved.
Conversely, in 2007, Robert Bridson released a mere one-page paper. Despite its brevity, it has garnered nearly 1,000 citations and can be fully comprehended in under ten minutes. This paper solves a ubiquitous challenge in simulations and computer graphics: how to distribute objects randomly without them clustering too closely.
The Problem: Randomness vs. Order
Imagine you are procedurally generating a forest. If you use basic random sampling to place your trees, you encounter an immediate issue: trees will overlap some trees will be placed directly on top of one another.
To fix this, we need a way to enforce a minimum distance between any two points. A set of points that satisfies this constraint is known as a Poisson disk distribution.
Why not just use rejection sampling?
A naive approach would be to "throw darts" at the map and reject any point that falls within the minimum distance of an existing point. However, this is inefficient because:
- Without a specialized data structure, checking collisions takes linear time.
- As the space fills up, the rejection rate rapidly approaches 100%.
Bridson’s Algorithm
To solve this efficiently, Bridson proposed an algorithm that works in -dimensional space with a desired minimum distance .
1. The Setup
First, partition the space into a grid where each cell has a side length of: This specific size ensures that each grid cell can contain at most one point.
2. The Process
The algorithm maintains a list called active.
3. Sampling the Annulus
To find a new point, we sample an annulus (a ring) centered at with an inner radius and an outer radius . To do this uniformly:
- Generate a random unit vector .
- Pick a value uniformly from the interval .
- The final sample point is calculated as:
Note: In 2D, picking is as simple as choosing an angle . In higher dimensions, you can normalize a vector composed of samples from a normal distribution.
Enhancing the Algorithm
There are two primary ways to reduce the number of iterations needed to fill the space. While the first is specific to 2D, the second is more general.
The "Parental" Optimization (2D)
When the algorithm generates a point from a parent point , we gain useful information. When we later sample the annulus around , there is a specific "cone" of angles that we can ignore because any point in that region would inevitably be too close to .
The Geometry of the Forbidden Cone: The cone is centered at angle with a total width of :
The function is critical here. Depending on the distance between and , the boundary of the forbidden zone is determined by either the inner or outer circle of the annulus. The transition occurs when the distance between points crosses .
Implementation Steps:
- Store the
parentof every generated point. - Calculate and for the current point relative to its parent .
- Generate the sample angle only from the range outside the window.
Performance Comparison
| Method | Iterations Required | Complexity | Notes |
|---|---|---|---|
| Standard Bridson | Higher | Baseline efficiency | |
| Parental Opt. | Significantly Lower | Faster convergence in 2D |
(Based on trials with and )
Final Considerations
While the parental optimization is powerful in 2D, its utility in higher dimensions is limited:
- Storage: It would require storing more contact vectors.
- Diminishing Returns: The volume of the intersection between an annulus and a sphere becomes proportionally smaller as dimensions increase.
One could theoretically store "children" as well as "parents" to prune even more of the annulus, but this would increase memory overhead and slow down the selection of .