| 1 |
\DocumentMetadata{} |
| 2 |
%% $Id: pst-massspring-doc.tex 1191 2025-12-18 09:53:56Z herbert $ |
| 3 |
\documentclass[fontsize=11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false, |
| 4 |
headings=small, headinclude=false,footinclude=false,twoside]{pst-doc} |
| 5 |
\usepackage{pst-gears} |
| 6 |
\usepackage{pst-plot} |
| 7 |
\usepackage{animate} |
| 8 |
\usepackage{pst-tools,pst-solides3d,pst-massspring} |
| 9 |
\let\PSTfileversion\fileversion |
| 10 |
\let\PSTfiledate\filedate |
| 11 |
|
| 12 |
|
| 13 |
\addbibresource{\jobname.bib} |
| 14 |
|
| 15 |
\renewcommand\bgImage{\begin{pspicture}(-1,-0.5)(4,2) |
| 16 |
\psElectromagnet |
| 17 |
\end{pspicture}} |
| 18 |
|
| 19 |
\addbibresource{\jobname.bib} |
| 20 |
\usepackage{enumitem} |
| 21 |
\setlist{nosep} |
| 22 |
\begin{document} |
| 23 |
|
| 24 |
\title{\texttt{pst-massspring}} |
| 25 |
\subtitle{Spring and mass; v.\PSTfileversion} |
| 26 |
\author{Manuel Luque \\ Herbert Voß} |
| 27 |
\docauthor{} |
| 28 |
\date{\today} |
| 29 |
\settitle |
| 30 |
|
| 31 |
\def\DatsSystem{ % valeurs par défaut utilisées dans cet exemple |
| 32 |
/kR 7.5 def |
| 33 |
/L0 5 def |
| 34 |
/m1 0.5 def /m2 2 def |
| 35 |
/radius1 m1 1 3 div exp def /radius2 m2 1 3 div exp def |
| 36 |
/Gravity 9.8 def |
| 37 |
/dl0 m2 Gravity mul kR div def |
| 38 |
/mu m1 m2 mul m1 m2 add div def |
| 39 |
/w0 kR mu div sqrt 180 mul 6.283185 div def % en degrees |
| 40 |
/T0 6.283185 kR mu div sqrt div def % période |
| 41 |
% /t@ 0 def |
| 42 |
/z20 radius1 radius2 add L0 add m2 Gravity mul kR div add def |
| 43 |
/Z@ m2 Gravity mul kR div |
| 44 |
t@ w0 mul cos mul L0 add radius1 add radius2 add def |
| 45 |
/zG0 m2 z20 mul m1 m2 add div def |
| 46 |
/zG 0.5 Gravity mul t@ 2 exp mul zG0 add def |
| 47 |
/Z1 zG m2 m1 m2 add div Z@ mul sub def |
| 48 |
/Z2 Z@ Z1 add def |
| 49 |
/zR1 Z1 neg radius1 sub def |
| 50 |
/zR2 Z2 neg radius2 add def |
| 51 |
% les tensions |
| 52 |
/Tension2 kR zR2 zR1 sub L0 add mul def |
| 53 |
/Tension1 kR zR2 zR1 sub L0 add mul neg def |
| 54 |
}% |
| 55 |
|
| 56 |
\part{Representation of a spring in pseudo-perspective} |
| 57 |
Timothy Van Zandt's pst-coil package (later expanded by subsequent |
| 58 |
maintainers) is primarily dedicated to the perspective representation |
| 59 |
of springs and offers numerous options. However, despite the number |
| 60 |
of options, these cannot fully satisfy physicists. Indeed, the two options |
| 61 |
`coilwidth`, which sets the spring diameter, and `coilheight`, which |
| 62 |
sets the distance between two coils—that is, the helix pitch—do not |
| 63 |
account for the fact that if the spring length is changed by |
| 64 |
compressing or stretching it, the number of coils remains the same, |
| 65 |
and the distance between the coils, as well as the spring diameter, a |
| 66 |
re modified. The \Lcs{psMassSpring} command allows for consideration of |
| 67 |
the physical behavior of a spring. |
| 68 |
|
| 69 |
\section{Initial state of the spring} |
| 70 |
|
| 71 |
\newcommand\bille{% |
| 72 |
\psset{linewidth=0.02,fillstyle=solid,fillcolor=blue!70} |
| 73 |
\pscircle[linecolor=blue](0,0){0.5} |
| 74 |
\psarc[linecolor=black](0,0){0.425}{-110}{90} |
| 75 |
\psarc[linecolor=black](0,0){0.3}{-90}{70} |
| 76 |
\psarc[linecolor=black](0,0){0.2}{-70}{60}} |
| 77 |
%%%% |
| 78 |
\newcommand\billeB{% |
| 79 |
\pscircle(0,0){0.5} |
| 80 |
\psarc(0,0){0.425}{-110}{90} |
| 81 |
\psarc(0,0){0.3}{-90}{70} |
| 82 |
\psarc(0,0){0.2}{-70}{60}} |
| 83 |
|
| 84 |
|
| 85 |
\begin{exampleM}{The default spiral} |
| 86 |
\begin{pspicture}[showgrid](-2,-2)(14,2)\psframe(-2,-2)(14,2) |
| 87 |
\psSpiral[N=20,li=10,R=0.5,alpha=20,dl=0.5,linewidth=0.05]{*-*}(0,0)(11,0) |
| 88 |
\psline[linewidth=0.5\pslinewidth](0.5,0)(0.5,1.25) |
| 89 |
\psline[linewidth=0.5\pslinewidth](10.5,0)(10.5,1.25) |
| 90 |
\psline[arrowsize=0.2,arrowinset=0.1]{<->}(0.5,1)(10.5,1)\uput[u](5.5,1){li=10 cm} |
| 91 |
\psline[linewidth=0.5\pslinewidth](0,0)(0,1.25) |
| 92 |
\psline[arrowsize=0.2,arrowinset=0.1]{>-}(-0.22,1)(0.5,1)\uput[u](0.25,1){dl} |
| 93 |
\psline[linewidth=0.5\pslinewidth](11,0)(11,1.25) |
| 94 |
\psline[arrowsize=0.2,arrowinset=0.1]{-<}(10.5,1)(11.25,1)\uput[u](10.75,1){dl} |
| 95 |
\end{pspicture} |
| 96 |
\end{exampleM} |
| 97 |
|
| 98 |
The same spring stretched by 5 cm. |
| 99 |
|
| 100 |
\begin{exampleM}{A stretched spiral} |
| 101 |
\begin{pspicture}[showframe](-2,-2)(14,2) |
| 102 |
\psSpiral[N=20,li=10,R=0.5,alpha=20,dl=0.5,linewidth=0.05]{*-*}(-2,0)(14,0) |
| 103 |
\psline[linewidth=0.5\pslinewidth](-1.5,0)(-1.5,1.25) |
| 104 |
\psline[linewidth=0.5\pslinewidth](13.5,0)(13.5,1.25) |
| 105 |
\psline[arrowsize=0.2,arrowinset=0.1]{<->}(-1.5,1)(13.5,1)\uput[u](5.5,1){L=15 cm} |
| 106 |
\psline[linewidth=0.5\pslinewidth](-2,0)(-2,1.25) |
| 107 |
\psline[arrowsize=0.2,arrowinset=0.1]{>-}(-2.25,1)(-1.5,1)\uput[u](-1.75,1){dl} |
| 108 |
\psline[linewidth=0.5\pslinewidth](14,0)(14,1.25) |
| 109 |
\psline[arrowsize=0.2,arrowinset=0.1]{-<}(13.5,1)(14.25,1)\uput[u](13.75,1){dl} |
| 110 |
\end{pspicture} |
| 111 |
\end{exampleM} |
| 112 |
|
| 113 |
\newpage |
| 114 |
\subsection{Parameters} |
| 115 |
\verb+\psSpiral[N=10,li=5,R=0.5,alpha=15,dl=0,nS=25](x1,y1)(x2,y2)+ |
| 116 |
|
| 117 |
|
| 118 |
The default values are: |
| 119 |
\begin{description}[nosep] |
| 120 |
\item[\Lkeyset{N=10}]: number of turns; |
| 121 |
\item[\Lkeyset{li=5}]: initial length; |
| 122 |
\item[\Lkeyset{R=0.5}]: initial radius of the spring; |
| 123 |
\item[\Lkeyset{dl=0}]: length of any attachments at the ends; |
| 124 |
\item[\Lkeyset{alpha=15}]: angle of the projection direction (see below); |
| 125 |
\item[\Lkeyset{nS=25}]: for the plot, number of points per turn. |
| 126 |
\end{description} |
| 127 |
|
| 128 |
|
| 129 |
\begin{center} |
| 130 |
\psset{unit=0.75} |
| 131 |
\def\nFrames{44}% 44 images |
| 132 |
\def\calc{% |
| 133 |
/Z0 -16 def |
| 134 |
/OMEGA 20 0.1 div sqrt def % pulsation des oscillations |
| 135 |
/Period TwoPi OMEGA div def % 0.4442883 |
| 136 |
/ti \rt\space def |
| 137 |
/ZR Z0 -5 OMEGA RadtoDeg ti mul cos mul add def } |
| 138 |
\begin{animateinline}[controls,loop,% |
| 139 |
begin={\begin{pspicture}(-2,1)(2,-23)}, |
| 140 |
end={\end{pspicture}}]{5}% 5 images/s |
| 141 |
\multiframe{\nFrames}{rt=0+0.01}{\psframe(-2,1)(2,-23) |
| 142 |
\psframe[fillstyle=hlines,linestyle=none,hatchcolor=black](-1,0)(1,0.2) |
| 143 |
\psline(-1,0)(1,0)\psdot(0,0) |
| 144 |
\psgrid[subgriddiv=0,griddots=10,gridlabels=0pt] |
| 145 |
\psSpiral[dl=0.5,R=0.5,alpha=25,N=20,li=10,linewidth=0.05](0,0)(! 0 \calc ZR) |
| 146 |
\rput(! 0 \calc ZR 0.5 sub){\bille}% |
| 147 |
}% |
| 148 |
\end{animateinline} |
| 149 |
\end{center} |
| 150 |
|
| 151 |
\newpage |
| 152 |
|
| 153 |
\section{Other examples} |
| 154 |
|
| 155 |
\begin{exampleM}{Example 1} |
| 156 |
\psset{unit=0.9} |
| 157 |
\begin{pspicture}[showgrid](-2,0)(16,15) |
| 158 |
\psSpiral(0,0)(0,15) |
| 159 |
\psSpiral[linecolor=blue,N=20,R=0.5,linewidth=0.1, |
| 160 |
alpha=-20,dl=1,arrowinset=0.1]{<->}(7,2)(11,10) |
| 161 |
\psSpiral[linecolor=red,N=20,R=0.5](13,5)(15,1) |
| 162 |
\end{pspicture} |
| 163 |
\end{exampleM} |
| 164 |
|
| 165 |
|
| 166 |
\begin{exampleM}{Example 2} |
| 167 |
\psset{unit=0.9} |
| 168 |
\begin{pspicture}[showgrid](-0.5,-5)(16.5,5) |
| 169 |
\psSpiral[linecolor=blue,N=25,R=1,li=5,dl=0.5,alpha=-20,doubleline=true](0,3)(16,3) |
| 170 |
\psset{alpha=25} |
| 171 |
\psSpiral[linecolor=red,N=8,R=0.5,li=5,dl=0](0,0)(4,0) |
| 172 |
\psSpiral[linecolor=black,N=8,R=0.5,li=5,dl=0](16,0) |
| 173 |
\psSpiral[linecolor=blue,N=15.5,R=0.5,li=5,dl=0.5,alpha=0](0,-2)(16,-2) |
| 174 |
\end{pspicture} |
| 175 |
\end{exampleM} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
\section{Some explanations} |
| 180 |
\begin{center} |
| 181 |
\includegraphics{images/image0} |
| 182 |
\end{center} |
| 183 |
|
| 184 |
Parametric equations of the cylindrical helix: |
| 185 |
|
| 186 |
\begin{align} |
| 187 |
x_H&=x_0+R\cos(2\pi{}t)\\ |
| 188 |
y_H&=x_0+R\sin(2\pi{}t)\\ |
| 189 |
z_H&=z_0+\mathrm{p}t |
| 190 |
\end{align} |
| 191 |
|
| 192 |
$R$ is the radius of the cylinder and $p$ is the pitch of the helix. |
| 193 |
This helix is a projected onto the $Oyz$ plane (or a plane parallel to it) |
| 194 |
along a direction $\overrightarrow{u}(\cos\alpha,0,\sin\alpha)$. |
| 195 |
The parametric equations of a |
| 196 |
line in direction u and passing through a point $P(x_H,y_H,z_H)$ on the helix are |
| 197 |
|
| 198 |
\begin{align} |
| 199 |
x&=x_H+\lambda\cos\alpha\\ |
| 200 |
y&=y_H\\ |
| 201 |
z&=z_H+\lambda\sin\alpha |
| 202 |
\end{align} |
| 203 |
|
| 204 |
he intersection of one of these lines with the $Oyz$ plane gives the expression for $\lambda$: |
| 205 |
|
| 206 |
\[ |
| 207 |
0=x_H+\lambda\cos\alpha \Longrightarrow \lambda=-\frac{x_H}{\cos\alpha} |
| 208 |
\] |
| 209 |
|
| 210 |
The coordinates are: |
| 211 |
|
| 212 |
\begin{align} |
| 213 |
x&=0\\ |
| 214 |
y&=y_H\\ |
| 215 |
z&=z_H-x_H\tan\alpha |
| 216 |
\end{align} |
| 217 |
|
| 218 |
\begin{align} |
| 219 |
x&=0\\ |
| 220 |
y&=y_0+R\sin(2\pi{}t)\\ |
| 221 |
z&=z_0+\mathrm{p}t-\Big(x_0+R\cos(2\pi{}t)\Big)\tan\alpha |
| 222 |
\end{align} |
| 223 |
|
| 224 |
For the 2D representation, we will take: |
| 225 |
|
| 226 |
\begin{align} |
| 227 |
X&=z_0+\mathrm{p}t-\Big(x_0+R\cos(2\pi{}t)\Big)\tan\alpha\\ |
| 228 |
Y&=y_0+R\sin(2\pi{}t) |
| 229 |
\end{align} |
| 230 |
|
| 231 |
If the spring has a straight attachment at each end of length $\mathrm{d}l$, |
| 232 |
then $z_0=\mathrm{d}l$. |
| 233 |
|
| 234 |
\begin{align} |
| 235 |
X&=\mathrm{d}l+\mathrm{p}t-\Big(x_0+R\cos(2\pi{}t)\Big)\tan\alpha\\ |
| 236 |
Y&=y_0+R\sin(2\pi{}t) |
| 237 |
\end{align} |
| 238 |
|
| 239 |
We want the starting point of the helix to be on the axis $(X=\mathrm{d}l,Y=0)$. |
| 240 |
We deduce $x_0$ by setting $t = 0$: |
| 241 |
|
| 242 |
\[ |
| 243 |
x_0=-R |
| 244 |
\] |
| 245 |
|
| 246 |
The equations for the 2D projection of the helix are: |
| 247 |
|
| 248 |
\begin{align} |
| 249 |
X&=\mathrm{d}l+\mathrm{p}t-\Big(-R+R\cos(2\pi{}t)\Big)\tan\alpha\\ |
| 250 |
Y&=R\sin(2\pi{}t) |
| 251 |
\end{align} |
| 252 |
|
| 253 |
For the spring, the number of turns, its initial radius, and its initial length must be specified, that is, |
| 254 |
when it is neither compressed nor stretched. When the spring is stretched or compressed, its length changes, of course, |
| 255 |
but also its radius, albeit less perceptibly; the \Lcs{psMassSpring} |
| 256 |
command takes this into account. |
| 257 |
From the initial length and the number of turns, the initial pitch |
| 258 |
of the spring can be deduced. |
| 259 |
|
| 260 |
\begin{verbatim} |
| 261 |
/NbreSpires \psk@NbreSpires def % nombre de spires |
| 262 |
/Alpha \psk@Alpha def % direction de projection |
| 263 |
/R_0 \psk@RayonInitial \pst@number\psunit mul def |
| 264 |
/dl \psk@dl \pst@number\psunit mul def |
| 265 |
/l_0 \psk@LongueurInitiale \pst@number\psunit mul def |
| 266 |
/nS \psk@nS def % nombre de points par spire |
| 267 |
/Pas_0 l_0 NbreSpires div def |
| 268 |
\end{verbatim} |
| 269 |
|
| 270 |
The length of a coil, which remains constant, is calculated |
| 271 |
using the following relationship: |
| 272 |
|
| 273 |
\[ |
| 274 |
l=2\pi\sqrt{R_0^2+\left(\frac{\mathrm{p_0}}{2\pi}\right)^2} |
| 275 |
\] |
| 276 |
|
| 277 |
|
| 278 |
$R_0$ and $p_0$ are respectively the radius and the initial pitch. |
| 279 |
|
| 280 |
When the spring is under load, its length is calculated using the |
| 281 |
coordinates of its ends, taking into account, if necessary, the |
| 282 |
length of the end strands. From this new length, the new pitch is |
| 283 |
deduced, followed by the current radius of the spring and the |
| 284 |
parametric equations of the helix. |
| 285 |
|
| 286 |
|
| 287 |
\begin{verbatim} |
| 288 |
% longueur de l'hélice sur un tour |
| 289 |
% = sqrt(4*pi^2*R^2+p^2) |
| 290 |
/Longueur_Helice_pas 39.47842 R_0 dup mul mul Pas_0 dup mul add sqrt def |
| 291 |
% R=1/(2*pi)*sqrt(L^2-p^2) |
| 292 |
/Radius 0.1591549 Longueur_Helice_pas dup mul Pas dup mul sub sqrt mul def |
| 293 |
/xH {Radius 360 t mul cos mul Radius sub} def |
| 294 |
/yH {Radius 360 t mul sin mul} def |
| 295 |
/zH {Pas t mul dl add} def |
| 296 |
\end{verbatim} |
| 297 |
|
| 298 |
\clearpage |
| 299 |
|
| 300 |
\part{Mass and spring} |
| 301 |
|
| 302 |
\section{Basics} |
| 303 |
\begin{center} |
| 304 |
\begin{pspicture}(-3,-0.5)(3,1.5) |
| 305 |
\psset{unit=1,dimen=middle} |
| 306 |
\psSpiral[R=0.4,N=15,l0=5]{-}(-2.5,0)(2.5,0) |
| 307 |
\psline{<->}(-2.5,1)(2.5,1) |
| 308 |
\uput[u](0,1){$l_0$} |
| 309 |
%\psgrid[subgriddiv=0,gridcolor=lightgray,griddots=10,gridlabels=0pt,unit=1]% |
| 310 |
\end{pspicture} |
| 311 |
\end{center} |
| 312 |
\begin{center} |
| 313 |
\includegraphics{images/image1} |
| 314 |
\end{center} |
| 315 |
|
| 316 |
\section{Equations of Motion} |
| 317 |
This is an exercise I found in two physics textbooks: |
| 318 |
“Lagrangian Dynamics” by Dare A. Wells \parencite[p. 12--13]{wells1967} |
| 319 |
and under the title “System of two masses in elastic interaction and |
| 320 |
free fall” exercise E25-1 in \textcite{perez2011}. |
| 321 |
The latter offers a solution but |
| 322 |
does not take into account the respective radii of the masses. |
| 323 |
|
| 324 |
The spring, with initial (unstretched) length $l_0$, is massless and |
| 325 |
has a spring constant $k$. The two balls have respective masses and |
| 326 |
radii $m_1$, $r_1$ and $m_2$, $r_2$. |
| 327 |
|
| 328 |
\[ |
| 329 |
m_2g=k\Big(\big(z_2(0)-z_1(0)\big)-(r_1+r_2)-l_0\Big) |
| 330 |
\] |
| 331 |
|
| 332 |
$z_1(0)=0$ due to the choice of the axis origin, we deduce $z_2(0)$: |
| 333 |
|
| 334 |
\[ |
| 335 |
z_2(0)=(r_1+r_2)+l_0+\frac{m_2g}{k} |
| 336 |
\] |
| 337 |
|
| 338 |
and the position of the system's center of mass: |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
\[ |
| 343 |
z_G(0)=\frac{m_2}{m_1+m_2}\Big((r_1+r_2)+l_0+\frac{m_2g}{k}\Big) |
| 344 |
\] |
| 345 |
|
| 346 |
|
| 347 |
At any given time $t$, the spring length is: |
| 348 |
|
| 349 |
|
| 350 |
\[ |
| 351 |
l(t)=z_2(t)-z_1(t)-(r_1+r_2) |
| 352 |
\] |
| 353 |
|
| 354 |
and its extension (or compression): |
| 355 |
|
| 356 |
\[ |
| 357 |
\Delta l(t)=l(t)-l_0 |
| 358 |
\] |
| 359 |
|
| 360 |
The fundamental relationship of dynamics applied to each of the two balls gives: |
| 361 |
|
| 362 |
\[ |
| 363 |
m_1\ddot{z_1}=\hphantom{-}k\big((z_2-z_1)-(r_1+r_2)-l_0\big) + m_1g |
| 364 |
\] |
| 365 |
|
| 366 |
\[ |
| 367 |
m_2\ddot{z_2}=-k\big((z_2-z_1)-(r_1+r_2)-l_0\big) + m_2g |
| 368 |
\] |
| 369 |
|
| 370 |
\begin{equation} |
| 371 |
\ddot{z_1}=\hphantom{-}\frac{k}{m_1}\big((z_2-z_1)-(r_1+r_2)-l_0\big) + g |
| 372 |
\end{equation} |
| 373 |
|
| 374 |
\begin{equation} |
| 375 |
\ddot{z_2}=-\frac{k}{m_2}\big((z_2-z_1)-(r_1+r_2)-l_0\big) + g |
| 376 |
\end{equation} |
| 377 |
|
| 378 |
We choose as variables $Z=z_2-z_1$, $\ddot{Z}=\ddot{z_2}-\ddot{z_1}$. |
| 379 |
|
| 380 |
\[ |
| 381 |
\ddot{Z}=-k\Big(Z-(r_1+r_2)-l_0\Big)\Big(\frac{1}{m_1}+\frac{1}{m_2}\Big) |
| 382 |
\] |
| 383 |
|
| 384 |
By setting $\mu=\dfrac{m_1m_2}{m_1+m_2}$, the differential equation in $Z$ becomes: |
| 385 |
|
| 386 |
|
| 387 |
\[ |
| 388 |
\ddot{Z}+\frac{k}{\mu}Z=\frac{k}{\mu}\big((r_1+r_2)+l_0\big) |
| 389 |
\] |
| 390 |
|
| 391 |
$\omega_0^2=\dfrac{k}{\mu}$ |
| 392 |
|
| 393 |
\[ |
| 394 |
\ddot{Z}+\omega_0^2Z=\omega_0^2(r_1+r_2+l_0) |
| 395 |
\] |
| 396 |
|
| 397 |
Given the initial conditions: $Z(0)=z_2(0)$ and $\dot{Z}(0)=0$, the solution to this equation is: |
| 398 |
|
| 399 |
\[ |
| 400 |
Z(t)=\frac{m_2g}{k}\cos\omega_0t+r_1+r_2+l_0 |
| 401 |
\] |
| 402 |
|
| 403 |
We can deduce $z_1(t)$ and $z_2(t)$, knowing that: |
| 404 |
|
| 405 |
\[ |
| 406 |
z_G(t)=\frac{m_1z_1(t)+m_2z_2(t)}{m_1+m_2} |
| 407 |
\] |
| 408 |
|
| 409 |
therefore |
| 410 |
|
| 411 |
\[ |
| 412 |
z_1(t)=z_G(t)-\frac{m_2}{m_1+m_2}Z(t) |
| 413 |
\] |
| 414 |
|
| 415 |
Therefore: |
| 416 |
|
| 417 |
|
| 418 |
\[ |
| 419 |
z_G(t)=\frac{1}{2}gt^2+z_G(0) |
| 420 |
\] |
| 421 |
|
| 422 |
And that: |
| 423 |
|
| 424 |
\[ |
| 425 |
z_2(t)=z_1(t)+Z(t)=z_G(t)+\frac{m_1}{m_1+m_2}Z(t) |
| 426 |
\] |
| 427 |
|
| 428 |
\section{The macro \nxLcs{pstMassSpring}} |
| 429 |
|
| 430 |
The "pst-massspring" package contains only one command, \Lcs{psMassSpring}\Largs{options}, |
| 431 |
whose options and default values are as follows: |
| 432 |
|
| 433 |
\begin{enumerate}[nosep] |
| 434 |
\item \texttt{t=0}: time in seconds;; |
| 435 |
\item \texttt{m1=0.5}: mass of (1) in kg; |
| 436 |
\item \texttt{m2=2}: mass of (2) in kg; |
| 437 |
\item \texttt{k=7.5}: spring constant N/m; |
| 438 |
\item \texttt{l0=5}: initial length of the spring. |
| 439 |
\end{enumerate} |
| 440 |
|
| 441 |
|
| 442 |
The radii are calculated from the masses (we assume both are made of steel). |
| 443 |
This package was written to create animations; here are two, the first |
| 444 |
with default values. |
| 445 |
|
| 446 |
To save space the following animations are not included in this documentation. |
| 447 |
We show only the code and an image how it looks if viewd with the Adobe Acrobat |
| 448 |
pdf-viewer: |
| 449 |
|
| 450 |
|
| 451 |
\begin{codeblockA}[breakable,title=Code for two animations] |
| 452 |
\begin{tabularx}{\linewidth}{ X X } |
| 453 |
\begin{center} |
| 454 |
\psset{unit=0.75} |
| 455 |
\begin{animateinline}[controls,loop, |
| 456 |
begin={\begin{pspicture}(-3,2)(2,-27)}, end={\end{pspicture}}]{10}% 10 images/s |
| 457 |
\multiframe{200}{rt=0.00+0.02, n=0+1}{% |
| 458 |
\psset{unit=0.5} |
| 459 |
\ifnum\n < 10 |
| 460 |
\psMassSpring[t=0]% delay switch closed |
| 461 |
\else |
| 462 |
\psMassSpring[t=\rt]% |
| 463 |
\fi |
| 464 |
\psgrid[subgriddiv=0,gridcolor=orange,griddots=10,gridlabels=0pt,unit=2]% |
| 465 |
}% |
| 466 |
\end{animateinline} |
| 467 |
\end{center} |
| 468 |
& |
| 469 |
\begin{center} |
| 470 |
\psset{unit=0.75} |
| 471 |
\begin{animateinline}[controls,loop, |
| 472 |
begin={\begin{pspicture}(-3,2)(2,-27)}, end={\end{pspicture}}]{10}% 10 images/s |
| 473 |
\multiframe{200}{rt=0.00+0.02, n=0+1}{% |
| 474 |
\psset{unit=0.5} |
| 475 |
\ifnum\n < 10 |
| 476 |
\psMassSpring[t=0,m1=1,m2=1,k=10]% switch closed |
| 477 |
\else |
| 478 |
\psMassSpring[t=\rt,m1=1,m2=1,k=10]% |
| 479 |
\fi |
| 480 |
\psgrid[subgriddiv=0,gridcolor=orange,griddots=10,gridlabels=0pt,unit=2]% |
| 481 |
}% |
| 482 |
\end{animateinline} |
| 483 |
\end{center} |
| 484 |
\end{tabularx} |
| 485 |
\end{codeblockA} |
| 486 |
|
| 487 |
\begin{center} |
| 488 |
\includegraphics[width=0.75\linewidth]{images/image3} |
| 489 |
\end{center} |
| 490 |
|
| 491 |
|
| 492 |
\section{Helper macro} |
| 493 |
|
| 494 |
\begin{exampleM}{Electromagnet with switch} |
| 495 |
\begin{pspicture}(-1,-0.5)(4,2) |
| 496 |
\psElectromagnet |
| 497 |
\end{pspicture} |
| 498 |
\qquad |
| 499 |
\begin{pspicture}(-1,-0.5)(4,2) |
| 500 |
\psset{t=1}\psElectromagnet |
| 501 |
\end{pspicture} |
| 502 |
\end{exampleM} |
| 503 |
|
| 504 |
|
| 505 |
\section{Animations} |
| 506 |
It is easier to create an \Lext{gif}-Animation than a \Lext{pdf} one. The latter |
| 507 |
needs the AdobeReader to run it on screen. The \Lext{gif} file can be viewed as |
| 508 |
part of a \Lext{html} page or as a standalone image. |
| 509 |
|
| 510 |
For the \Lext{gif} file we have to create a document with single pdf pages |
| 511 |
and then convert this to \Lext{gif}. The following example creates a 310 pages |
| 512 |
document by running \Lprog{lualatex}. It is also possible with \Lprog{latex} |
| 513 |
and the \Lprog{dvips}$\rightarrow$\Lprog{ps2pdf} route, which is, of course, |
| 514 |
faster than \Lprog{lualatex}. |
| 515 |
|
| 516 |
\begin{codeblockA}[title=Creating a gif animation from single pdf's] |
| 517 |
\DocumentMetadata{} |
| 518 |
\documentclass[pstricks]{standalone} |
| 519 |
\usepackage{pst-massspring,multido} |
| 520 |
\begin{document} |
| 521 |
\multido{\i=0+1}{10}{% |
| 522 |
\begin{pspicture}(-3,2)(2,-24)% |
| 523 |
\psset{unit=0.5} |
| 524 |
\psMassSpring[t=0,m1=1,m2=1,k=10]% |
| 525 |
\psgrid[subgriddiv=0,gridcolor=orange,griddots=10,gridlabels=0pt,unit=2]% |
| 526 |
\end{pspicture}} |
| 527 |
\multido{\n=0.00+0.01}{300}{% nearly 2 periodes |
| 528 |
\begin{pspicture}(-3,2)(2,-24) |
| 529 |
\psset{unit=0.5} |
| 530 |
\psMassSpring[t=\n,m1=1,m2=1,k=10]% |
| 531 |
\psgrid[subgriddiv=0,gridcolor=orange,griddots=10,gridlabels=0pt,unit=2]% |
| 532 |
\end{pspicture}} |
| 533 |
\end{document} |
| 534 |
\end{codeblockA} |
| 535 |
|
| 536 |
|
| 537 |
The conversion to \Lext{gif} is done by the program \Lprog{magick}, formerly known |
| 538 |
as \Lprog{convert}: |
| 539 |
|
| 540 |
\begin{codeblock}[minted language=bash, title=Converting pdf to gif] |
| 541 |
magick convert -delay 5 -density 100x100 -alpha remove anim1.pdf -loop 0 anim1.gif |
| 542 |
\end{codeblock} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
\printbibliography |
| 548 |
|
| 549 |
\printindex |
| 550 |
\end{document} |