如何在 TikZ 中绘制模数螺旋

如何在 TikZ 中绘制模数螺旋

我想在 TikZ 中绘制以下螺旋线。您能帮我画一下吗? 模数算术螺旋

太感谢了

答案1

不确定 TiZ 是为此而制作的,但这里是开始使用tikz-3dplot

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\tdplotsetmaincoords{75}{80}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,line join=round,
    declare function={R=2;a=1;}]
    \pgfmathsetmacro{\tmin}{\tdplotmainphi/360-2}
    \draw[cyan,thick,-{Stealth[bend]}] plot[variable=\t,domain=\tmin+3.49:\tmin+4.1,samples=21,smooth]
        ({R*cos(360*\t)},{R*sin(360*\t)},{a*\t});
    \foreach \tt in {0,...,3}
    {\draw[cyan,thick] plot[variable=\t,domain=\tmin+\tt:\tmin+0.51+\tt,samples=41,smooth]
        ({R*cos(360*\t)},{R*sin(360*\t)},{a*\t});}
    \path foreach \t in {1,2,3} 
     {
      ({R*cos(72*\t)},{R*sin(72*\t)},{-2*a})
      edge[thick,red] ({R*cos(72*\t)},{R*sin(72*\t)},{3*a})};
    \foreach \tt in {0,...,3}
    {\draw[line cap=butt,white,double=cyan,double distance=0.8pt] 
        plot[variable=\t,domain=\tmin+0.49+\tt:\tmin+1.01+\tt,samples=41,smooth]
        ({R*cos(360*\t)},{R*sin(360*\t)},{a*\t});}
    \path foreach \t in {0,4}     
    {({R*cos(72*\t)},{R*sin(72*\t)},{-2*a})
      edge[white,double=red,double distance=0.8pt]
      ({R*cos(72*\t)},{R*sin(72*\t)},{3*a})};
    \path foreach \t in {-8,-7,...,11}
     {({R*cos(72*\t)},{R*sin(72*\t)},{a*\t/5})
      node[circle,fill,inner sep=1pt,
        label={[anchor={(Mod(\t,5)==0?135:(Mod(\t,5)==1?180:45))}]:$\t$}]
        (c\t){}};   
    \draw[line cap=butt,white,double=cyan,double distance=0.8pt] 
        plot[variable=\t,domain=\tmin-0.15:\tmin+0.01,samples=21,smooth]
        ({R*cos(360*\t)},{R*sin(360*\t)},{a*\t});   
\end{tikzpicture}   
\end{document}

在此处输入图片描述

答案2

这是一个自动化解决方案。我们定义一个新命令\modhelix,它接受 3 个参数,其中一个是可选的。可选参数是循环次数(默认值为 4)。第一个必需参数是模数;第二个是起始值(在螺旋线的底部)。例如,命令

\modhelix{5}{-8}\hspace{2cm}\modhelix[3]{6}{-11}

将产生以下输出:

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}

\newcommand{\modhelix}[3][4]{% #1=number of cycles, #2=modulus, #3=start value
    \begin{tikzpicture}
    \foreach \k in {1,...,#1}{% 
        \foreach \j [evaluate=\j as \m using (\j-1)/#2*360+90/#2, 
                     evaluate=\j as \n using \j/#2*360+90/#2,
                     evaluate=\j as \c using int(#3+(#2*(\k-1)+\j-1))] in {1,...,#2}%
        {\draw[white, double=red, double distance=1.5pt, line width=1pt] ({2*cos(\m)},{2*\k+sin(\m)+\m/180-.3}) -- ++ (0,2);
        \draw[white, double=cyan, double distance=1.5pt, line width=1pt, domain=\m-90/#2:\n-90/#2, smooth, variable=\t] plot ({2*cos(\t)}, {2*\k+sin(\t)+\t/180});
        \fill ({2*cos(\m)},{2*\k+sin(\m)+\m/180}) circle[radius=3pt] node[below right]{\c};}}
    \end{tikzpicture}}

\begin{document}

\[
\modhelix[4]{5}{-8}\hspace{2cm}\modhelix[3]{6}{-11}
\]

\end{document}

相关内容