I want to graph a curve on the flat torus, but not on the entire R^2
plane, but on the square [0,1]x[0,1]
.
For this, I have created a "do...while" with only the initial data of the rational slope. This is:
let m=p/q
let fx(u)=m(1-u) and fy(u)=(1-u)/m
x=0
DO
y=fx(x)
draw (x,0) -- (1,y);
x=fy(y)
draw (0,y) -- (x,1);
WHILE (x=1)
I apologize for the big mistakes in my code. I just wrote my idea since I don't know how to do it in LaTeX, using TikZ for example. How can I do it?
I already did it manually, but it is not the most optimal. Trying to put m=3/4
is supposed to output the following:
I don't want to code where I have to plot everything manually like the following:
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[red] (0,0) -- (1,3/4);
\draw[red] (0,3/4) -- (1/3,1);
\draw[red] (1/3,0) -- (1,1/2);
\draw[red] (0,1/2) -- (2/3,1);
\draw[red] (2/3,0) -- (1,1/4);
\draw[red] (0,1/4) -- (1,1);
\draw (0,0) -- (1,0) -- (1,1) -- (0,1) -- (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
\clip (0,0) rectangle (1,1)
before the drawing. If you don't want to affect all the drawing, put this in a scope.10/11
for example. For this reason I proposed a more programmable idea, the problem is that I don't know how to program (things like for, do while, etc) in latex.while
loop in TikZ, as far as I know. You would have to compute first how many loops you'll have (or stop when you're back to the starting point) and use aforeach
loop. Then, applying your alg doesn't seem that hard if you only want the lines. As for the grid now, it could be a bit more tricky because you need it to adjust automatically. Intersting question, indeed, worth the time spent on it.