Circle Packing

Circle packing with size and size gradientsCircle packing with size and color gradients

Regular circle packing in 2-dimensions is a long-solved problem that has been approached from several points of view. For example, in 1773 Joseph Louis Lagrange proved that hexagonal packing is the optimal arrangement.

More recently, random polygon packing - of which circle packing is a special case - has become popular among professionals, and hobbyists such as myself who enjoy creating mathematical art.

While the math is interesting, the intent here is to use random circle packing as a model problem to investigate approaches to parallel processing.

Generally, the procedure is to create a circle with random location and properties (e.g. color and size). If it is created in a location where it collides with another circle it may be moved a number of times to different locations to see if it can fit somewhere else. If not, it is simply destroyed. Fast collision detection is the heart of the problem. If no place can be found for circles of a certain size, a smaller size is used for subsequent trials.

Software I use controls for color, size, growth, and filled vs hollow, and speed.

Color of the circles can be based on the following:

The color method used can be altered at runtime for a variety of effects.

Size of the circles can be based on the following:

The size method used can be altered at runtime for a variety of effects.

Growth can be controlled in two ways:

Growth visible in videos and images is only for aesthetic purposes (the latter option). Growth to fill maximum space (the former option) happens silently on the GPU and is not visible.

Circles may be drawn as filled or hollow. It's more interesting to grow them hollow (like expending bubbles) and then fill them when the growth animation has completed.

Maximizing Speed is the main reason for this project. So tradeoffs are driven towards keping framerates "interactive", such as 10-30 per second. It amazes me that personal computers can generate 256 circles and test them against hundreds of thousands of existing circles to determine placement at such speeds.

There are also more technical considerations, such as:

There are several other types of random spece-filling algorithms. Here are some examples:

Parallel circle-packing computation, with growthParallel circle-packing computation, with growth
Recursive circle packing with animationRecursive circle packing with animation

Related Information