繪製平坦的環面

繪製平坦的環面

我想在平坦的圓環上繪製一條曲線,但不是在整個R^2平面上,而是在正方形上[0,1]x[0,1]

為此,我創建了一個“do...while”,僅包含有理斜率的初始數據。這是:

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)

對於我的程式碼中的重大錯誤,我深表歉意。我只是寫下了我的想法,因為我不知道如何在 LaTeX 中使用蒂克茲例如。我該怎麼做?

我已經手動完成了,但這不是最佳的。嘗試 putm=3/4應該輸出以下內容:

在此輸入影像描述

我不想在必須手動繪製所有內容的地方進行編碼,如下所示:

\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}

答案1

這是一個選項。我定義了一個有三個參數的命令\flattorus

  1. (可選)TikZ 圖片中正方形的邊長,單位為公分。我將 4 設為預設值,但當然您可以輕鬆更改它。
  2. 將正方形分割成的列數。
  3. 將正方形分割成的行數。
\documentclass{article}
\usepackage{tikz}
\newcounter{mx}
\newcounter{my}
\newlength{\squareside}
\newcommand*{\flattorus}[3][4]{%
    \setcounter{mx}{#2}
    \setcounter{my}{#3}
    \addtocounter{mx}{-1}
    \addtocounter{my}{-1}
    \setlength{\squareside}{#1 cm}

    \begin{tikzpicture}[x=\dimexpr\squareside/#2, y=\dimexpr\squareside/#3]
        \draw[thick] (0,0) rectangle (#2,#3);
        \foreach \x in {0, ..., \value{mx}}
            \foreach \y in {0, ..., \value{my}}{
                \draw (\x,\y) -- ++(0,1);
                \draw (\x,\y) -- ++(1,0);
                \draw[red, thick] (\x,\y) -- ++(1,1);
            };
        \node[below left] at (0,0) {0};
        \node[below] at (#2,0) {1};
        \node[left] at (0,#3) {1};
        \foreach \x in {1, ..., \value{mx}}
            \node[below] at (\x,0) {\x/#2};
        \foreach \y in {1, ..., \value{my}}
            \node[left] at (0,\y) {\y/#3};
    \end{tikzpicture}
}
\begin{document}
\flattorus{3}{4}
\flattorus{5}{2}
\flattorus[2]{2}{3}
\end{document}

答案2

@Vincent (+1) 發布了一個很好的解決方案,但這已經在進行中,所以我想我會將其作為替代方案發布。

這是一個宏\flattorus,它需要兩個參數(和一個附加的可選參數)來繪製平面環面。在圓環上\flattorus[<scale factor>]{y}{x}繪製斜率線。y/x預設比例為 2,產生邊長為 2 公分的正方形。

例如,\flattorus{3}{4}\qquad\flattorus{5}{3}產生:

在此輸入影像描述

\flattorus[6]{10}{11}生產

在此輸入影像描述

\documentclass{article}

\usepackage{tikz}

\newcommand{\flattorus}[3][2]{\begin{tikzpicture}[scale=#1]
    \foreach \k[evaluate=\k as \j using int(\k-1)] in {2,...,#2}{
        \draw[gray!30] ({(\j)/#2},0)node[black, below]{$\frac{\j}{#2}$}--++(0,1);}
    \foreach \k[evaluate=\k as \j using int(\k-1), evaluate=\k as \p using #2*#3] in {2,...,#3}{\xdef\xy{\p}
        \draw[gray!30] (0,{(\j)/#3})node[black, left]{$^{\j}\!/\!_{#3}$}--++(1,0);}
    \foreach \k[evaluate=\k as \j using int(\k-1), evaluate=\k as \x using frac(\k*#3/\xy), evaluate=\k as \y using frac(\k*#2/\xy)] in {1,...,\xy}{
        \draw[red, thick]({frac(\j*#3/\xy)},{frac(\j*#2/\xy)})--({\x+less(\x,1/\xy)},{\y+less(\y,1/\xy)});}
    \draw (0,0)node[below left]{0}--(1,0)node[below]{1}--(1,1)--(0,1)node[left]{1}--cycle;
    \end{tikzpicture}}

\begin{document}

\flattorus{3}{4}\qquad\flattorus{5}{3}

\flattorus[6]{10}{11}

\end{document}

答案3

試試這個程式碼:

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}[scale=10]
        \draw[gray!30,xstep=.3333,ystep=.25] (0,0) grid (1,1);
        
        \draw[red,line width=2pt] (0,0) -- (1,3/4);
        \draw[red,line width=2pt] (0,3/4) -- (1/3,1);
        \draw[red,line width=2pt] (1/3,0) -- (1,1/2);
        \draw[red,line width=2pt] (0,1/2) -- (2/3,1);
        \draw[red,line width=2pt] (2/3,0) -- (1,1/4);
        \draw[red,line width=2pt] (0,1/4) -- (1,1);
        \foreach \x in {0,1/3,2/3,1}
        \draw (\x,.02)--(\x,-.02) node[below] {\bfseries $\x$};
        \foreach \y in {0,1/4,1/2,3/4,1}
        \draw (.02,\y)--(-.02,\y) node[left] {\bfseries $\y$};  
    \end{tikzpicture}
\end{document}

輸出:

在此輸入影像描述

相關內容