Packed spheres
Spheres of random sizes filling a cylinder, joined by a smooth union so that neighbors that touch merge
with a fillet. The source is at Examples/PackedSpheres/main.cpp.
Fig. 30 3,000 spheres in a cylinder, joined by a smooth union.
Building the packing
Each sphere’s center is drawn by rejection sampling: uniformly in the box around a cylinder along \(x\), five times as long as its radius, and kept only if it lies inside the cylinder. Its radius is drawn too. A BVHSmoothUnion holds them in a pool and builds a BVH over their boxes:
const BVHSmoothUnion<T, SphereSDF<T>, K, SmoothMinOp<T>> packing(pool, spheres, boxes, blendLength);
A point is evaluated against the spheres near it only, and the two nearest values are blended with the smooth minimum, so spheres within the blend length of each other merge (see BVH-accelerated unions). The program prints the number of spheres, the box and the value at two points.
Looking at it
The example ends with Render::view(packing, pool, argc, argv); X cuts the cylinder open to show the
spheres inside.
The window needs SDL2 and is built with make VIEWER=SDL2 or cmake -DEBGEOMETRY_VIEWER=SDL2 (see
The viewer window (EBGEOMETRY_VIEWER)); otherwise, and with --no-view or without a display, view() prints why
and returns. Drag to orbit and scroll to zoom; the window lists its other keys (see
The viewer’s keys).
Building and running
See Building for how to compile it with CMake, GNU Make, or a direct compiler invocation. Built for a GPU (see Running on a GPU), the window renders on the device.
cd Examples/PackedSpheres
./PackedSpheres.ex