Image

Crea una animación de una cicloide

En este video explico cómo realizar una animación de una cicloide en un archivo en pdf y utilizando solamente código.

        \documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{ifthen}
\usepackage{animate}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.17}
\newcounter{angle}
\setcounter{angle}{0}
\begin{document}
  
  
 \begin{center}
  
   \begin{animateinline}[loop, poster = first, controls]{30}
  \whiledo{\theangle<361}{
   \begin{tikzpicture}[scale=0.7]
    \begin{axis}[width=19cm,height=7cm,xlabel=$x$, ylabel=$y$,
        xmin=-0.2,xmax=20.8495,
        ymin=-0.15,ymax=6.8,
               axis x line=center,axis y line=center,]
               
    \addplot[domain=0:360,samples=75,thick, cyan] ({3*(0.01745329251*x-sin(x))},{3*(1-cos(x))});  
% pi/180=0.01745329251
% x=3(x-sin(x))               
% y=3(1-cos(x))             
% centro (3x,3) 
        
    \pgfmathparse{multiply(3*0.01745329251,\theangle)}
    \xdef\xcentro{\pgfmathresult}
    
    \coordinate (c) at (axis cs: \xcentro,3);
    \node[red] at (c) {$\bullet$};
        
    \pgfmathsin{\theangle}
    \pgfmathparse{multiply(add(multiply(0.01745329251,\theangle),-\pgfmathresult),3)}
    \xdef\xcoor{\pgfmathresult}
              
    \pgfmathcos{\theangle}
        \pgfmathparse{multiply(add(1,-\pgfmathresult),3)}
    \xdef\ycoor{\pgfmathresult}
              
    \coordinate (P) at (axis cs:\xcoor,\ycoor);
    \node[red] at (P) {$\bullet$};
    
    \draw[blue] (c) -- (P);
    
     
    
    \node [blue,above=3mm of c] {$C$};
    
    \node [red,above=3mm of P] {$P$};
    
    \addplot[domain=0:720,samples=75,thick,blue] ({3*(cos(x))+\xcentro},{3*sin(x)+3)});  
    %\draw[blue] (c) circle (2.5cm);
    
    \end{axis}
     \end{tikzpicture}
  \stepcounter{angle}
  \ifthenelse{\theangle<361}{
    \newframe
    }{
  \end{animateinline}
  }
}


    \end{center}


\end{document}
        

© Profesor Favián Arenas. 2023. Diseñado por HTML Codex