(centered-circle-path (realpart pos2) (imagpart pos2) r2) (centered-circle-path (realpart pos1) (imagpart pos1) r1) (draw-apollonian-gasket c3 r3 c1 r1 (car lc41) (cadr lc41) (- steps 1))))) (draw-apollonian-gasket c2 r2 c3 r3 (car lc41) (cadr lc41) (- steps 1)) (draw-apollonian-gasket c1 r1 c2 r2 (car lc41) (cadr lc41) (- steps 1)) ( defun draw-apollonian-gasket (c1 r1 c2 r2 c3 r3 steps) (r4 (/ 1 (solve-equation curv1 curv2 curv3))) ( defun draw-forth-circle (pos1 r1 pos2 r2 pos3 r3) In order to draw the picture of the Apollonian gasket we use the Vecto library which provides an easy way for drawing the picture. To find to position we use the complex numbers provided by Common Lisp and the same function defined above: For this post I'm only using the first solution (that's why the program is incomplete!!!). We use values to return multiple values implied by the solution of the equation. This function is used to solve the equation shown above. We can calculate the position of the 4th circle (shown in red) by using the following function: By multiplying each curvature value k n with a complex number that represents the position of the circle we can obtain a complex number with the position of the remaining circle. The curvature can be calculated as 1/radius of the circle.Īccording to the Wikipedia article this formula could also be used to determine the position of the 4th circle. Given that k n is the curvature of the circle n. It is named after Greek mathematician Apollonius of Perga.īasically the Apollonian gasket is generated by finding the 4th circle that is tangent to a given tree tangent circles and repeating the process recursively.Īccording to Wikipedia in order to find the position and the radius of the 4th circle we use the Descartes theorem which implies that we can apply the following formula: In mathematics, an Apollonian gasket or Apollonian net is a fractal generated from three circles, any two of which are tangent to one another. The Wikipedia entry for the Apollonian Gasket defines it as: In this post I'm going to show a simple, yet incomplete, program to draw the Apollonian Gasket using Common Lisp and Vecto.