Skip to content

kfahn22/Apollonian-Gasket

Repository files navigation

Apollonian-Gasket

“The Kiss Precise” by Frederick Soddy

Four circles to the kissing come The smaller are the benter. The bend is just the inverse of The distance from the center. Though their intrigue left Euclid dumb, There’s now no need for rule of thumb. Since zero bend’s a dead straight line, And concave bends have minus sign, The sum of the squares of all four bends Is half the square of their sum.

This repo contains code to render the Apollonian gasket. The Apollonian gasket is a special kind of circle packing where you start with a big circle and then fit smaller circles inside it, each touching the big circle and each other.

Descartes' formula is a mathematical formula that helps us understand the relationships between circles when they're packed together like in the Apollonian gasket.

Here's the idea: for any three circles that are mutually tangent (meaning they touch each other externally), there's a neat formula that relates the curvatures (or how "bendy" they are) of these circles. The formula is:

$(k_1 + k_2 + k_3 + k_4)^2 = 2(k_1^2 + k_2^2 + k_3^2 + k_4^2)$

Here, $k1$, $k2$, and $k3$ are the curvatures of the circles. The curvature of a circle is just the reciprocal of its radius. So if you have a big circle with radius $R$, its curvature is $1/R$.

Now, in the Apollonian gasket, we start with three circles inside a larger circle. These circles are tangent to each other and the big circle. Using Descartes' theorem, we can find the curvatures of these circles and use them to find the curvatures of the smaller circles we pack inside them, and so on.

The cool thing about this theorem is that it applies not just to three circles but to any number of circles that are all tangent to each other. So as we keep adding smaller circles into the gaps, we can keep using Descartes' theorem to understand how they all fit together. It's named after the ancient Greek mathematician Apollonius, who was really good at studying shapes and curves.

The code for most of the versions is adapted from Daniel Shiffman's Apollonian Coding Challenge.

The code for the nested version is from Richard Bourne (I have updated the syntax a little bit.) The python and circle inversion code sets actual pixels, so it can't be adapted like Daniel's code. The python code is from user FB36 posted in ActiveStateCode. I obtained the circle inversion code by posting the python code in ChatGPT3.5 and asking it to port to p5.js. It did a pretty decent job--I only had to modify the loop slightly.

🌄 Gallery

Apollonian gasket with 6 pentagons

Apollonian gasket with polar pentagons
Apollonian gasket with Phyllotaxis

Apollonian gasket with Phyllotaxis
3D Apollonian gaskets

Apollonian gasket with spheres
Apollonian gasket with Annular Chains

Apollonian gasket filled with Annular Chains
Apollonian gasket with flowers

Apollonian gasket with flowers
Apollonian gasket with butterflies

Apollonian gasket with butterflies
Apollonian gasket with Coding Train logo

Apollonian gasket with Coding Train logo
Steiner chain filled with gaskets

Annular chain filled with gaskets

gif

References

Processing code examples https://openprocessing.org/browse/?time=anytime&type=all&q=apollonian# https://openprocessing.org/sketch/1878906 Processing

D3 Zoomable circle packing

Github Apollonian

https://tex.stackexchange.com/questions/539896/another-way-to-draw-steiners-chain

About

Code to render the Apollonian gasket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published