圆环动画中的斜线

圆环动画中的斜线

我想在Latex上画出下面的情况,但我不知道怎么做!

在页面底部,有一个“移动”的无理密集缠绕线的圆环,就像这样视频

在这个圆环上方,我需要一个立方体,立方体中有一个“移动”的密集管道(圆柱体)。圆环中的线和立方体中的管道同时以相同的速度移动。

答案1

编译

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\tikzset{declare function={torusx(\u,\v,\R,\r)=cos(\u)*(\R + \r*cos(\v)); 
torusy(\u,\v,\R,\r)=(\R + \r*cos(\v))*sin(\u);
torusz(\u,\v,\R,\r)=\r*sin(\v);
vcrit1(\u,\th)=atan(tan(\th)*sin(\u));% first critical v value
vcrit2(\u,\th)=180+atan(tan(\th)*sin(\u));% second critical v value
vtest(\u,\v,\az,\el)=sin(-vcrit1(\u-\az,\el)+\v);
disc(\th,\R,\r)=((pow(\r,2)-pow(\R,2))*pow(cot(\th),2)+% 
pow(\r,2)*(2+pow(tan(\th),2)))/pow(\R,2);% discriminant
umax(\th,\R,\r)=ifthenelse(disc(\th,\R,\r)>0,asin(sqrt(abs(disc(\th,\R,\r)))),0);
}}
\pgfplotsset{visible stretch/.style={restrict expr to domain={vtest(atan2(rawy,rawx),%
ifthenelse(veclen(rawx,rawy)>\R,asin(rawz/\r),180-asin(rawz/\r)),\pgfkeysvalueof{/pgfplots/view/az},\pgfkeysvalueof{/pgfplots/view/el})}{-0.05:1.1}},
hidden stretch/.style={restrict expr to 
domain={vtest(atan2(rawy,rawx),%
ifthenelse(veclen(rawx,rawy)>\R,asin(rawz/\r),180-asin(rawz/\r)),\pgfkeysvalueof{/pgfplots/view/az},\pgfkeysvalueof{/pgfplots/view/el})}{-1.1:0.05}}}
\newsavebox\Torus
\sbox\Torus{\tikz{\pgfmathsetmacro{\R}{4}
\pgfmathsetmacro{\r}{1}
\begin{axis}[colormap/blackwhite,xmax=1.1*(\R+\r),xmin=-1.1*(\R+\r),
     ymax=1.1*(\R+\r),ymin=-1.1*(\R+\r),zmax=1.1*\r,zmin=-1.1*\r,
   view={40}{60},axis lines=none]
       \addplot3[surf,shader=interp,
       samples=61, point meta=z+sin(2*y),
       %surf,shader=flat,
       domain=0:360,y domain=0:360,
       z buffer=sort]
       ({torusx(x,y,\R,\r)}, 
        {torusy(x,y,\R,\r)}, 
        {torusz(x,y,\R,\r)});
\end{axis}}}
\begin{document}
\foreach \X [count=\Y] in {-20,-15,...,90}
{\begin{tikzpicture}
\pgfmathsetmacro{\R}{4}
\pgfmathsetmacro{\r}{1}
\begin{axis}[xmax=1.1*(\R+\r),xmin=-1.1*(\R+\r),
     ymax=1.1*(\R+\r),ymin=-1.1*(\R+\r),zmax=1.1*\r,zmin=-1.1*\r,
     view={40}{60},axis lines=none]
     \addplot3[very thick,samples y=0,domain=-25:\X,smooth,
     samples=6+5*\Y]  
        ({torusx({sqrt(30)*x},x,\R,\r)}, 
        {torusy({sqrt(30)*x},x,\R,\r)}, 
        {torusz({sqrt(30)*x},x,\R,\r)});    
     \node[opacity=0.8] at (0,0,0) {\usebox\Torus};
     \addplot3[very thick,samples y=0,domain=-25:\X,smooth,samples=6+5*\Y,
     visible stretch]  
        ({torusx({sqrt(30)*x},x,\R,\r)}, 
        {torusy({sqrt(30)*x},x,\R,\r)}, 
        {torusz({sqrt(30)*x},x,\R,\r)});
\end{axis}
\end{tikzpicture}}
\end{document}

pdflatex转换生成的 pdf 文件out.pdf

convert -density 200 -delay 34 -loop 0 -alpha remove out.pdf ani.gif

获取此动画 gif:

在此处输入图片描述 pdf 文件的质量要高得多,这是由于上传限制。这是生成的帧之一:

在此处输入图片描述

相关内容