File:WaveLongitudinal.gif

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

WaveLongitudinal.gif(427 × 469 pixels, file size: 1.16 MB, MIME type: image/gif, looped, 63 frames, 6.3 s)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: propagating longitudinal waves
Deutsch: longitudinale Wellen
Date
Source Own work
Author And1mu

Source Code[edit]

created with LaTeX and PGF/TikZ

Script to create the animation:

#!/bin/bash

set -eu
DIR="animate"
FILE="WaveLongitudinal"

NUM=0
rm -f ${DIR}/frame???.png
for ANG in $(seq -1.5 0.20 11) ; do
    echo "Creating frame $NUM ..."
    POS=$ANG
    echo $POS $ANG
    sed -i "s/\\\def\\\myt{.\+}/\\\def\\\myt{$POS}/" ${FILE}.tex
    pdflatex -shell-escape ${FILE}.tex 1> /dev/null
    echo "Convert to png ..."
    NUMSTR=$(printf "%03d" $NUM)
    convert -density 100 ${FILE}.svg -shave 3 ${DIR}/frame${NUMSTR}.png
    NUM=$(($NUM+1))
done
cd $DIR
convert -delay 10 -loop 10000 frame*.png  ${FILE}.gif
cd -

The code to create a single frame (WaveLongitudinal.tex):

\documentclass[crop,border=3,tikz,convert={outext=.svg,command=\unexpanded{pdf2svg
    \infile\space\outfile}},multi=false]{standalone}
\usepackage{ifthen}
\usetikzlibrary{math,decorations.pathmorphing,patterns}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\def\myt{5.1}
\def\mypi{3.141592653589793}

\newcommand{\spring}[2]{
  \def\s{0.015}
  \tikzmath{\l = ((#2)-(#1+8*\s))*9 ;}
  \draw[] (#1,0)--(#1+\s,0);
  \draw[decoration={aspect=0.33, segment length=\l,
    amplitude=2mm,coil},decorate] (#1+\s,0)--(#2,0);
}

\newcommand{\wave}[4]{
  \def\myA{#1}
  \def\mya{#2}
  \def\myB{#3}
  \def\myb{#4}
  \def\olda{0}

  \draw[ultra thick,blue,smooth,domain=0:10,samples=100] plot
  function {0.5*(\myA*exp(-\mya*(10-x-\myt)**2)+\myB*exp(-\myb*(x-\myt)**2))
  -1};

  \foreach \a in {0,0.5,...,10}{
    \tikzmath{\myy=
      0.2*(\myA*exp(-\mya*(10-\a-\myt)^2)+\myB*exp(-\myb*(\a-\myt)^2));
    }
    \tikzmath{\myv=
      0.5*(\mya*(10-\a-\myt)* \myA*exp(-\mya*(10-\a-\myt)^2)
      +\myb*(\a-\myt)*\myB*exp(-\myb*(\a-\myt)^2));
    }

    \tikzmath{\myoldy=
      0.2*(\myA*exp(-\mya*(10-\a+0.5-\myt)^2)+\myB*exp(-\myb*(\a-0.5-\myt)^2));
    }

    \ifthenelse{\lengthtest{\myy pt > 0.1 pt} \OR \lengthtest{\myy pt < -0.1 pt}}{
      \draw[red,->,tips=proper] (\a,0) -++ (\myy,0);
    }{
      \draw[red] (\a,0) -++ (\myy,0);
    }

    \draw[red,fill=white] (\a,0) circle (0.6mm);
    \begin{pgfonlayer}{foreground}
      \fill[red] (\a+\myy,0) circle (0.6mm);
    \end{pgfonlayer}
    \ifthenelse{\lengthtest{\a pt > 0 pt}}{
      \spring{\a-0.5+\myoldy}{\a+\myy};
    }
    % \pgfmathparse{\a==4?1:0}
    %\ifthenelse{\lengthtest{\myv pt > 0.1 pt} \OR \lengthtest{\myv pt < -0.1 pt}}{
    %  \draw[thick,->,tips=proper] (\a+\myy,1) -++ (\myv,0);
    %}{
    %  \draw[thick] (\a+\myy,1) -++ (\myv,0);
    %}
  }
}
\newcommand{\sinewave}[1]{
  \def\mypi{3.141592653589793}
  \def\myx{\myt}

  \draw[ultra thick,blue,smooth,domain=0:9.5,samples=40] plot
  function {0.7*sin(x-\myx)-1};
  \draw[ultra thick,dotted,blue,smooth,domain=9.5:10,samples=5] plot
  function {0.7*sin(x-\myx)-1};

  \foreach \a in {0,0.5,...,10}{
    \tikzmath{\myy=0.35*sin(180/\mypi*(\a-\myx));}
    \tikzmath{\myoldy=0.35*sin(180/\mypi*(\a-0.5-\myx));}
    \ifthenelse{\lengthtest{\myy pt > 0.1 pt} \OR \lengthtest{\myy pt < -0.1 pt}}{
      \draw[red,->,tips=proper] (\a,0) -++ (\myy,0);
    }{
      \draw[red] (\a,0) -++ (\myy,0);
    }
    \draw[red,fill=white] (\a,0) circle (0.6mm);
    \begin{pgfonlayer}{foreground}
      \fill[red] (\a+\myy,0) circle (0.6mm);
    \end{pgfonlayer}
    \ifthenelse{\lengthtest{\a pt > 0 pt}}{
      \spring{\a-0.5+\myoldy}{\a+\myy};
    }
  }
}

\begin{tikzpicture}[>=latex,scale=1]
  \begin{pgfonlayer}{background}
    \fill[white] (-0.5,-8) rectangle (10.5,4);
  \end{pgfonlayer}
  \clip (0,-8) rectangle (10,4);
  \begin{pgfonlayer}{foreground}
    \clip (0,-8) rectangle (10,4);
  \end{pgfonlayer}
  % \draw[thick,->] (0,-0.3) -- (0,2.8) node[above]{\Large $y$};
  %\draw[thick,->] (-0.1,0) -- (10.5,0) node[below]{\Large $x$};
  \foreach \a in {-1.5,-1,...,0}{
    \draw[dotted] (0,\a) -- (10,\a);
  }
  \wave{1}{5}{1}{5}
  \begin{scope}[shift={(0,-2.5)}]
    %\draw[thick,->] (0,-1.7) -- (0,1.8) node[above]{\Large $y$};
    %\draw[thick,->] (-0.1,0) -- (10.5,0) node[below]{\Large $x$};
    \foreach \a in {-2,-1.5,...,0}{
      \draw[dotted] (0,\a) -- (10,\a);
    }
    \wave{-1.5}{5}{1.5}{5}
  \end{scope}
  \begin{scope}[shift={(0,3)}]
    %\draw[thick,->] (0,-1.7) -- (0,1.8) node[above]{\Large $y$};
    %\draw[thick,->] (-0.1,0) -- (10.5,0) node[below]{\Large $x$};
    \foreach \a in {-2,-1.5,...,0}{
      \draw[dotted] (0,\a) -- (10,\a);
    }
    \wave{-1.3}{0.8}{1.4}{10}
  \end{scope}
  \begin{scope}[shift={(0,-5.5)}]
    %\draw[thick,->] (0,-1.7) -- (0,1.8) node[above]{\Large $y$};
    %\draw[thick,->] (-0.1,0) -- (10.5,0) node[below]{\Large $x$};
    \foreach \a in {-2,-1.5,...,0}{
      \draw[dotted] (0,\a) -- (10,\a);
    }
    \sinewave{-1.3}{0.8}{1.4}{10}
  \end{scope}
\end{tikzpicture}
\end{document}

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current14:38, 22 June 2016Thumbnail for version as of 14:38, 22 June 2016427 × 469 (1.16 MB)And1mu (talk | contribs)User created page with UploadWizard

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file: