0

I want to draw the following situation on Latex, but I don't know how!

In the bottom of the page, a torus with a "moving" irrational dense winding line, like in this video

And above this torus, I need a cube with a "moving" dense pipe (cylinder). Where the line in the torus and the pipe in cube move at the same time and speed.

  • Welcome to TeX-SE! The purpose of this site is to help you succeed with specific attempts, not to convert your directives into LaTeX code. First of all, what do you mean by "with LaTeX"? There are several packages that allow you, at least in principle, such things. Most notable for 3D purposes perhaps asymptote, which is an external program that allows you to embed LaTeX code. Anyway, the answers to this question show already many possibilities. They will allow you to get started. –  Jun 14 '19 at 01:39

1 Answers1

3

Compile

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

with pdflatex and convert the resulting pdf file out.pdf with

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

to get this animated gif:

enter image description here The pdf file has a much higher quality, the quality of this is due to upload restrictions. This is one of the frames generated:

enter image description here