现在,我经历了这个答案,但不幸的是,我没能理解太多。我的想法很简单。对有理数运行两个嵌套循环并绘制点。我所做的如下:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=5]
\node [fill, circle, inner sep=0.5pt] at (0,0) {};
\node [fill, circle, inner sep=0.5pt] at (1,1) {};
\foreach [evaluate=\n as \den using \n-1] \n in {2,...,85}
\foreach \m in {1,...,\den}
\node [fill, circle, inner sep=0.5pt] at ({\m/\n},{1/\n}) {};
\end{tikzpicture}
\end{document}
我被困在这gcd
部分。我不知道pgfmathsetmacro
和条件ifthenelse
语句的正确用法和语法。请帮忙。
答案1
我认为这就是你要找的东西。我用(比我们需要整数\pgfmathtruncatemacro
更好)编写了代码,并用条件语句编写了代码。\pgfmathsetmacro
\ifnum
\documentclass[tikz,border=2mm]{standalone}
\def\maxden{50} % maximum denominator
\begin{document}
\begin{tikzpicture}[scale=5]
\foreach\d in {2,...,\maxden} % denominators from 2 to maximum
{
\pgfmathtruncatemacro\maxnum{\d-1} % maximum numerator
\foreach\n in {1,...,\maxnum} % numerators from 2 to maximum
{
\pgfmathtruncatemacro\gcd{gcd(\n,\d)}
\ifnum\gcd = 1 % then the fraction is irreducible, so we draw a point
\fill (\n/\d,1/\d) circle (0.1pt);
\fi
}
}
\end{tikzpicture}
\end{document}