Note: I've already asked a question in a similar spirit to this, but I don't feel like I got my point across so here I am.
I am working on a program that draws the Apollonian gasket fractal. I need help with the complex Descartes theorem. It seems to work well when the curvatures are all positive, but it breaks when some of the curvatures are made negative to try to fix this. The square root in Descartes' theorem also breaks down.
For example, I'm currently trying to draw the gasket for the circles centered at $(1,0)$, $(-\frac{1}{2}, \frac{\sqrt{3}}{2})$, and $(\frac{-1}{2}, \frac{-\sqrt{3}}{2})$, all with radii $\frac{\sqrt{3}}{2}$, which all touch in an equilateral triangle.
I would expect a picture like this:
But I keep getting this:
Here's my algorithm:
- Initialize the Soddy circles.
- Use Descartes' theorem to find the two possible signed curvatures $k_{4}^{\pm}$ of the solution circles; I used this formula from the Wikipedia page: $k_{4}^{\pm} = k_1+k_2+k_3\pm 2\sqrt{|k_1k_2 + k_2k_3 + k_3k_1|}$. The absolute value avoids this being undefined due to negative curvature.
- Use the complex version of Descartes' theorem to find the two possible centers of the solution circles, using the equation from Wikipedia.
- Check if we already have drawn any of these circles.
- Take each of the new Soddy circles, and repeat from step 2.
If I were to guess, I'd say that the error has something to do with me either not using the proper signs for the curvature. I tried making the first circle's radius negative, as I've seen this elsewhere, but this seems to break it even more. I would appreciate your help getting this program to work.
Also, might the solution be to use an alternative algorithm/formula to find the circles' centers?