Last active
August 29, 2015 14:16
-
-
Save kpym/3630c2c68a21b0b6a2ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[tikz]{standalone} | |
\usetikzlibrary{math} | |
\tikzmath{ | |
function FordCircles(\a,\b,\n){ | |
int \p, \q; % ------------------------------ p and q are integers | |
for \q in {1,...,\n}{ % -------------------- 0 < q <= n | |
for \p in {\a*\q,...,\b*\q}{ % ----------- a < p/q < b <=> [aq] < p < [bq] | |
if gcd(\p,\q) == 1 then { % ------------ if the fraction is irreducible | |
\f = \p/\q; % ------------------------ evaluate the tuch point f = p/q | |
\r = 1/(2*\q*\q); % ------------------ evaluate the radius r = 1/2q^2 | |
{ | |
\draw[red] (\f,\r) circle(\r); % --- and draw the Ford circle at (f,r) | |
}; | |
}; | |
}; | |
}; | |
}; | |
} | |
\begin{document} | |
\begin{tikzpicture} | |
\draw[help lines,step=2mm] (-1,-0.1) grid (4,1.1); | |
% Draw the Ford circles | |
\tikzmath{FordCircles(-.9,3.9,8);} | |
\end{tikzpicture} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment