4

enter image description hereBonjour. I have this code for a conic pendulum. I want it to move (uniform rotation) through the ellipse. How can I modify the code?

\documentclass{article} 
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\begin{document}
\begin{tikzpicture}[scale=1, decoration={coil,aspect=0.6,segment length=1.5mm,amplitude=1.5mm}] 
\tikzset{ressort/.style={thick,gray,smooth}} 
\draw[ressort,decorate] (0,0)--++(-2,+5); 
\node at (-0.8,3) {$\ell$}; 
\draw [rounded corners=10pt,color=white,ball color=red,smooth] (0,0) circle (0.2); 
\draw [xshift=0.3cm,rotate around={180:(-0.4,2.2)},line width=1pt,-stealth] (1.8,1.7) arc (-30:210:0.3cm and 0.2cm) node[below left=0.4cm] {$\omega$};
\draw[dotted](-2,0) ellipse (2cm and 0.6cm);
\draw  (-2,-0.4)--++(0,5.4); 
\fill [pattern=north east lines,rotate=0] (-2.5,5) rectangle (-1.5,5.3); 
\draw[thick] (-2.5,5) --++ (1,0); 
\end{tikzpicture}
\end{document}
Bernard
  • 271,350
DINEDINE
  • 485

1 Answers1

7

Something like this?

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending,calc,decorations.pathmorphing,patterns}
\begin{document}
\foreach \X in {0,10,...,350}
{\begin{tikzpicture}[scale=1,ressort/.style={thick,gray}]
  \path[use as bounding box] (-2.5,-0.9) rectangle (2.5,5.5);
  \draw[dotted](0,0) circle[x radius=2cm, y radius=0.6cm];
  \ifnum\X<180
   \draw let \p1=($([yshift=1.2mm]\X:2cm and 0.6cm)-(0,5)$),\n1={veclen(\x1,\y1)} in 
   [ressort,decorate, decoration={coil,aspect=0.6,segment length=\n1/36,amplitude=1.5mm}] 
   (0,5)-- ([yshift=1.2mm]\X:2cm and 0.6cm) \ifdim\x1>0pt [right=1em] \else [left=1em] \fi node[midway] {$\ell$}; 
   \draw [ball color=red] 
   (\X:2cm and 0.6cm) circle[radius=0.2cm]; 
   \draw[-{stealth},thick] 
   ({0.3*cos(150)},1.7) arc (150:390:0.3cm and 0.2cm) node[below left=0.4cm] {$\omega$};
   \draw  (0,-0.4)--++(0,5.4); 
  \else
   \draw[-{stealth},thick] 
   ({0.3*cos(150)},1.7) arc (150:390:0.3cm and 0.2cm) node[below left=0.4cm] {$\omega$};
   \draw  (0,-0.4)--++(0,5.4); 
   \draw let \p1=($([yshift=1.2mm]\X:2cm and 0.6cm)-(0,5)$),\n1={veclen(\x1,\y1)} in 
   [ressort,decorate, decoration={coil,aspect=0.6,segment length=\n1/36,amplitude=1.5mm}] 
   (0,5)-- ([yshift=1.2mm]\X:2cm and 0.6cm) \ifdim\x1>0pt [right=1em] \else [left=1em] \fi node[midway] {$\ell$}; 
   \draw [ball color=red] 
   (\X:2cm and 0.6cm) circle[radius=0.2cm]; 
  \fi
  \fill [pattern=north east lines,rotate=0] (-0.5,5) rectangle (0.5,5.3); 
  \draw[thick] (-0.5,5) --++ (1,0); 
\end{tikzpicture}}
\end{document}

enter image description here

This is a version that produces the animation in pdf.

\documentclass{article} 
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{bending,calc,decorations.pathmorphing,patterns}
\begin{document}
\begin{center}
\begin{animateinline}[controls,buttonsize=0.5em,autoplay,loop]{2}
\multiframe{36}{i=0+1}{
 \begin{tikzpicture}[scale=1,ressort/.style={thick,gray}]
  \pgfmathtruncatemacro{\X}{\i*10}
  \path[use as bounding box] (-2.5,-0.9) rectangle (2.5,5.5);
  \draw[dotted](0,0) circle[x radius=2cm, y radius=0.6cm];
  \ifnum\X<180
   \draw let \p1=($([yshift=1.2mm]\X:2cm and 0.6cm)-(0,5)$),\n1={veclen(\x1,\y1)} in 
   [ressort,decorate, decoration={coil,aspect=0.6,segment length=\n1/36,amplitude=1.5mm}] 
   (0,5)-- ([yshift=1.2mm]\X:2cm and 0.6cm) \ifdim\x1>0pt [right=1em] \else [left=1em] \fi node[midway] {$\ell$}; 
   \draw [ball color=red] 
   (\X:2cm and 0.6cm) circle[radius=0.2cm]; 
   \draw[-{stealth},thick] 
   ({0.3*cos(150)},1.7) arc (150:390:0.3cm and 0.2cm) node[below left=0.4cm] {$\omega$};
   \draw  (0,-0.4)--++(0,5.4); 
  \else
   \draw[-{stealth},thick] 
   ({0.3*cos(150)},1.7) arc (150:390:0.3cm and 0.2cm) node[below left=0.4cm] {$\omega$};
   \draw  (0,-0.4)--++(0,5.4); 
   \draw let \p1=($([yshift=1.2mm]\X:2cm and 0.6cm)-(0,5)$),\n1={veclen(\x1,\y1)} in 
   [ressort,decorate, decoration={coil,aspect=0.6,segment length=\n1/36,amplitude=1.5mm}] 
   (0,5)-- ([yshift=1.2mm]\X:2cm and 0.6cm) \ifdim\x1>0pt [right=1em] \else [left=1em] \fi node[midway] {$\ell$}; 
   \draw [ball color=red] 
   (\X:2cm and 0.6cm) circle[radius=0.2cm]; 
  \fi
  \fill [pattern=north east lines,rotate=0] (-0.5,5) rectangle (0.5,5.3); 
  \draw[thick] (-0.5,5) --++ (1,0); 
\end{tikzpicture}}
\end{animateinline}
\end{center}
\end{document}

You can view it with Acrobat Reader. There you can also adjust the speed.

If you download the library tikzlibrary3dtools.code.tex from here and put it somewhere where TeX will find it, you can compile

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools,bending,calc,decorations.pathmorphing,patterns}
\begin{document}
\foreach \X in {0,10,...,350}
{\begin{tikzpicture}[scale=1]
  \path[use as bounding box] (-2.5,-0.9) rectangle (2.5,5.5);
  \begin{scope}[3d/install view={theta=70}]
   \path (0,0,5) coordinate (t) (0,0,3.2) coordinate (m) (0,0,0) coordinate (O);
   \path ({1.9*cos(\X)},{1.9*sin(\X)},0.3) coordinate (x)
    ({2*cos(\X)},{2*sin(\X)},0) coordinate (y);
   \begin{scope}[canvas is xy plane at z=0]
    \draw[dotted] circle[radius=2cm];
    \ifnum\X<180
     \draw let \p1=($(x)-(t)$),\n1={veclen(\x1,\y1)} in 
      [decorate,decoration={3d coil color=gray,aspect=0.35, 
      segment length=\n1/108, amplitude=1.5mm,3d complete coil}] 
      (x) -- (t) \ifdim\x1>0pt [right=1em] \else [left=1em] \fi node[midway] {$\ell$}; 
     \begin{scope}
     \pgflowlevelsynccm
     \draw[-{stealth},thick] 
      (m) + (150:0.3) arc (150:390:0.3cm) ;
     \end{scope} 
     \path (m)  node[left,yshift=-1.4cm] {$\omega$};
     \draw[shorten <=-4mm]  (O)--(t); 
    \else
     \begin{scope}
     \pgflowlevelsynccm
     \draw[-{stealth},thick] 
      (m) + (150:0.3) arc (150:390:0.3cm) ;
     \end{scope} 
     \path (m)  node[left,yshift=-1.4cm] {$\omega$};
     \draw[shorten <=-4mm]  (O)--(t); 
     \draw let \p1=($(x)-(t)$),\n1={veclen(\x1,\y1)} in 
      [decorate,decoration={3d coil color=gray,aspect=0.35, 
      segment length=\n1/108, amplitude=1.5mm,3d complete coil}] 
      (x) -- (t) \ifdim\x1>0pt [right=1em] \else [left=1em] \fi node[midway] {$\ell$}; 
    \fi
   \end{scope}
   \path[pattern=north east lines] (-0.5,0,5) rectangle (0.5,0,5.3); 
   \draw[thick] (-0.5,0,5) --++ (1,0,0); 
 \end{scope}
 \path[ball color=red] (y) circle[radius={2.5mm-sin(\X)*0.5mm}];
\end{tikzpicture}}
\end{document}

to get

enter image description here

  • Thanks for the answer. This is what I needed. Btw how can we increase the rotating velocity? – DINEDINE Dec 08 '19 at 15:23
  • 1
    @DINEDINE At this point, this creates an animated gif, and the velocity is set by the conversion. In more detail, it is the delay parameter in convert -density 300 -delay 34 -loop 0 -alpha remove multipage.pdf animated.gif from https://tex.stackexchange.com/a/136919/194703. How do you want to play the animation? There is also the animate package, which allows you to play it in pdf, and you can change the speed with the controls. –  Dec 08 '19 at 15:27
  • Actually I had a documentclass{book}, when I write your code into my text, that just draw four pendulum and no rotation. – DINEDINE Dec 08 '19 at 15:30
  • How can we do it with an animated package to be played in pdf? – DINEDINE Dec 08 '19 at 15:33
  • @DINEDINE I added an example. It is the second code, which will also work with the document class book. The third code is just for fun. –  Dec 08 '19 at 15:57
  • thank you @Schrodinger. – DINEDINE Dec 08 '19 at 16:45
  • how can I delete the adjusting speed button from your second code and make the pendulum move by itself. – DINEDINE Dec 08 '19 at 16:51
  • @DINEDINE If you use \begin{animateinline}[autoplay,loop]{2}, i.e. drop controls, then there won't be buttons. autoplay means it automatically plays the animation. –  Dec 08 '19 at 16:55
  • It works. Thank you – DINEDINE Dec 08 '19 at 16:58