mercredi 15 juin 2016

Oscillateurs parallèles couplés par des ressorts n°6

Voici une version avec 10 mobiles et 9 ressorts mais dont les positions et vitesses initiales sont aléatoires et ont été codées avec Postscript : c'est donc un listing plus court et une compilation un tout petit peu plus rapide.
Alexander Grahn m'a rappelé les différentes méthodes pour réaliser les animations avec le package animate(dont il est l'auteur), je l'en remercie :

\usepackage[method=icon]{animate}   %default with pdfTeX
\usepackage[method=widget]{animate} %default with dvips
\usepackage[method=ocg]{animate}

Aussi par

\begin{animateinline}[method=...

ou

\animategraphics[method=...

Il précise aussi que la méthode OCG est particulièrement avantageuse, s'il n'y pas d'autres éléments (texte, images) sur la même page.

On constate que les ressorts sont alignés verticalement lorsque le système est stabilisé, mais pas forcément au milieu.

Remarque : le Gif ne boucle pas, il faut donc rafraichir l'écran pour relancer l'animation (touche F5).

Les fichiers sont dans le dossier :

Le listing :

\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{pst-ode,pst-ressort,pst-plot}
\usepackage[method=ocg]{animate}
\title{Dix oscillateurs parallèles couplés par des ressorts}
% on introduit une force de frottement -f*vx
\date{15 juin 2016}
\author{Manuel Luque}
% manuel.luque27@gmail.com
\pagestyle{empty}
\begin{document}
%\maketitle
\def\mobileA{\pscustom[fillstyle=solid,fillcolor=red,unit=0.2]{\psline(-0.5,0.1)(-2,0.1)(-2,1)(2,1)(2,0.1)
\psarcn(0,0.1){0.5}{0}{180}
\moveto(-0.2,0.1)
\psarc(0,0.1){0.2}{180}{360}
\psline(0.2,0.1)(-0.2,0.1)}}
\def\mobileB{\psframe[fillstyle=solid,fillcolor=yellow,unit=0.2](-2,-0.5)(2,0.5)}
\def\mobileC{\pscustom[fillstyle=solid,fillcolor=red,unit=0.2]{\psline(0.5,-0.1)(2,-0.1)(2,-1)(-2,-1)(-2,-0.1)(-0.5,-0.1)
\psarcn(0,-0.1){0.5}{180}{0}
\moveto(0.2,-0.1)
\psarc(0,-0.1){0.2}{0}{180}
\psline(-0.2,-0.1)(0.2,-0.1)}}
% 10 mobiles
%  0  1   2   3   4    5   6   7   8   9  %  10   11  12   13   14   15   16   17  18   19
% x1  x2  x3  x4  x5  x6  x7  x8  x9  x10 %  x'1 x'2  x'3  x'4  x'5  x'6  x'7  x'8 x'9  x'10
\def\DixOscillateurs{x[10]|x[11]|x[12]|x[13]|x[14]|x[15]|x[16]|x[17]|x[18]|x[19]| %
                                                km*(x[1]-x[0])*(1-L0/sqrt(distance^2+(x[1]-x[0])^2))-cf*x[10]|%
                                               -km*(x[1]-x[0])*(1-L0/sqrt(distance^2+(x[1]-x[0])^2))+km*(x[2]-x[1])*(1-L0/sqrt(distance^2+(x[2]-x[1])^2))-cf*x[11]|%
                                               -km*(x[2]-x[1])*(1-L0/sqrt(distance^2+(x[2]-x[1])^2))+km*(x[3]-x[2])*(1-L0/sqrt(distance^2+(x[3]-x[2])^2))-cf*x[12]|%
                                               -km*(x[3]-x[2])*(1-L0/sqrt(distance^2+(x[3]-x[2])^2))+km*(x[4]-x[3])*(1-L0/sqrt(distance^2+(x[4]-x[3])^2))-cf*x[13]|%
                                               -km*(x[4]-x[3])*(1-L0/sqrt(distance^2+(x[4]-x[3])^2))+km*(x[5]-x[4])*(1-L0/sqrt(distance^2+(x[5]-x[4])^2))-cf*x[14]|%
                                               -km*(x[5]-x[4])*(1-L0/sqrt(distance^2+(x[5]-x[4])^2))+km*(x[6]-x[5])*(1-L0/sqrt(distance^2+(x[6]-x[5])^2))-cf*x[15]|%
                                               -km*(x[6]-x[5])*(1-L0/sqrt(distance^2+(x[6]-x[5])^2))+km*(x[7]-x[6])*(1-L0/sqrt(distance^2+(x[7]-x[6])^2))-cf*x[16]|%
                                               -km*(x[7]-x[6])*(1-L0/sqrt(distance^2+(x[7]-x[6])^2))+km*(x[8]-x[7])*(1-L0/sqrt(distance^2+(x[8]-x[7])^2))-cf*x[17]|%
                                               -km*(x[8]-x[7])*(1-L0/sqrt(distance^2+(x[8]-x[7])^2))+km*(x[9]-x[8])*(1-L0/sqrt(distance^2+(x[9]-x[8])^2))-cf*x[18]|%
                                               -km*(x[9]-x[8])*(1-L0/sqrt(distance^2+(x[9]-x[8])^2))-cf*x[19]}%
\def\initCond{initCond}
\begin{center}
\def\nFrames{250}% 250 images
\begin{animateinline}[controls,
                     begin={\begin{pspicture}(-7,-10)(7,10)},
                     end={\end{pspicture}}]{17}% 17 images/s
\pstVerb{rrand srand
        /initCond {10 { rand 2147483647 div 6 mul -3 add  } repeat
                   10 { rand 2147483647 div 20 mul -10 add} repeat
                   } def
%% k/m = km =4pi^2 = 39.4784176
         /km 39.4784176 def
         /L0 1 def
         /distance 2 def
% coefficient de frottement / masse = cf
         /cf 0.75 def
        }%
\pstODEsolve[algebraic,varsteptol=1e-6]{mobile0123456789}{0 1 2 3 4 5 6 7 8 9}{0}{10}{\nFrames}{\initCond}{\DixOscillateurs}
\pstVerb{
/posX1 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i get} for
       ]def
/posX2 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 1 add get} for
       ]def
/posX3 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 2 add get} for
       ]def
/posX4 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 3 add get} for
       ]def
/posX5 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 4 add get} for
       ]def
/posX6 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 5 add get} for
       ]def
/posX7 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 6 add get} for
       ]def
/posX8 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 7 add get} for
       ]def
/posX9 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 8 add get} for
       ]def
/posX10 [0 10 [mobile0123456789] length 10 sub {/i exch def
            [mobile0123456789] i 9 add get} for
       ]def
}%
\multiframe{\nFrames}{i=0+1}{%
\psframe*[linecolor=cyan!20](-7,-10)(7,10)
\psline[linewidth=0.05](-7,9.1)(7,9.1)
\psline[linewidth=0.05](-7,7)(7,7)
\psline[linewidth=0.05](-7,5)(7,5)
\psline[linewidth=0.05](-7,3)(7,3)
\psline[linewidth=0.05](-7,1)(7,1)
\psline[linewidth=0.05](-7,-1)(7,-1)
\psline[linewidth=0.05](-7,-3)(7,-3)
\psline[linewidth=0.05](-7,-5)(7,-5)
\psline[linewidth=0.05](-7,-7)(7,-7)
\psline[linewidth=0.05](-7,-9.1)(7,-9.1)
\rput(!posX1 \i\space get 9){\mobileA}
\rput(!posX2 \i\space get 7){\mobileB}
\rput(!posX3 \i\space get 5){\mobileB}
\rput(!posX4 \i\space get 3){\mobileB}
\rput(!posX5 \i\space get 1){\mobileB}
\rput(!posX6 \i\space get -1){\mobileB}
\rput(!posX7 \i\space get -3){\mobileB}
\rput(!posX8 \i\space get -5){\mobileB}
\rput(!posX9 \i\space get -7){\mobileB}
\rput(!posX10 \i\space get -9){\mobileC}
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=blue]{*-*}(!posX1 \i\space get 9)(!posX2 \i\space get 7)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=red]{*-*}(!posX2 \i\space get 7)(!posX3 \i\space get 5)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=green]{*-*}(!posX3 \i\space get 5)(!posX4 \i\space get 3)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=magenta]{*-*}(!posX4 \i\space get 3)(!posX5 \i\space get 1)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=cyan]{*-*}(!posX5 \i\space get 1)(!posX6 \i\space get -1)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=magenta]{*-*}(!posX6 \i\space get -1)(!posX7 \i\space get -3)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=green]{*-*}(!posX7 \i\space get -3)(!posX8 \i\space get -5)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=red]{*-*}(!posX8 \i\space get -5)(!posX9 \i\space get -7)
\psRessort[N=20,li=0.5,R=0.15,alpha=20,dl=0.4,linecolor=blue]{*-*}(!posX9 \i\space get -7)(!posX10 \i\space get -9)
}
\end{animateinline}
\end{center}
\end{document}

Aucun commentaire:

Enregistrer un commentaire