我有一张由 Z/11 中的 x 和 y 组成的图表。是否可以以编程方式绘制斜率为 2 的线?
例如从 (0,0) 到 (5,10) 并且 (6,12) 将因为模 11 而变成 (6,1)。就像下面的图一样。
对于该图表,我使用以下代码。但我必须手动计算起点和终点。
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (11,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,11);
\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis
\foreach \x in {0,1,...,10}{% Two indices running over each
\foreach \y in {0,1,...,10}{% node on the grid we have drawn
\node[draw,circle,inner sep=1pt,fill] at (\x,\y) {};
% Places a dot at those points
}
}
\draw [thin, blue,-latex] (Origin) -- (5,10);
\draw [thin, blue,-latex] (6,1) -- (10,9);
\end{tikzpicture}
答案1
您可以使用Mod(<num>,<base>)
函数来获取模数,但我不明白您是否希望在每个循环中使用它,所以这里是循环
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (11,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,11);
\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis
\foreach \x in {0,1,...,10}{% Two indices running over each
\foreach \y[evaluate=\y as \yi using {Mod(\y,11)}] in {0,1,...,15}{
\node[draw,circle,inner sep=1pt,fill] at (\x,\y) {};
\draw (0,0) -- (\x,\yi);
% Places a dot at those points
}
}
\end{tikzpicture}
\end{document}
我希望我理解正确,
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (11,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,11);
\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis
\draw (0,0) \foreach \x in {1,...,11}{
\foreach \y in {1,...,11}{
node[draw,circle,inner sep=1pt,fill] at (\x-1,\y-1) {}
-- ({Mod(\x,11)},{Mod(2*\x,11)})
}
};
\end{tikzpicture}
\end{document}