My son and I were recently watching Vi Hart’s wonderful “Doodling in Math Class” Video on Infinity Elephants. Around 1:30 in the video she starts talking about how to draw an Apollonian Gasket in a triangle:

This got me wondering about how to code this object. It’s not a new challenge. Lot’s of people have done it. You can even search Shapeways to find some amazing 3-D printed, 3-dimensional versions. But I couldn’t find much info on how its done. I did find an old discussion here where they were wondering how to do the same thing. (Nothing really useful there, except some nice references to hyperbolic Geometry-specifically a little paper by David Dumas-with a dead link to a program written by Curt McMullen.)

I’ll use Python when I have to, but my preferred method of construction is with the visual programming language Grasshopper, a plug-in for the CAD program Rhinoceros3D.  Clearly, the object I was trying to replicate is fractal, which means recursion is going to be unavoidable. That’s easy enough in Python, but it sucks in Grasshopper. The only way I know to do recursion in Grasshopper is with a 3rd party component. I think there are multiple options. The one I use is called “Hoopsnake.” It does the job, but for this kind of thing it’s extremely slooowwww. That’s OK, because to replicate the drawing in Vi’s video, I’m only going to do about 5 iterations.

It took a bit of experimenting, but eventually I got it down to a surprisingly small Grasshopper definition. The key was to use the CircleTanTanTan component, which automatically finds the circle that is tangent to three different input curves. For the Grasshopper savvy out there, here’s my definition:

Here’s what it produces….

…exactly what I wanted!!

Once I had that, it wasn’t hard to make all kinds of designs. Here are some Apollonian Spheres.

I even experimented with an Apollonian Pocket Watch Design!