4

I'm interested in creating a plot using TikZ or pgfplots together with the animate package.

The plot should consist of a square impulse that is moving along the z axis. As it moves it should lose its "squarness" and become a smoother impulse (see the image).

I suspect this could be done in two ways:

  1. Define an impulse function of time(\it) which would change accordingly.
  2. Draw a TikZ path with appropriate decorations that change with a parameter (\it).

How could this be done?

Wave dispersion

My first try:

\documentclass{article}
\usepackage{tikz,pgfplots}
 \usepackage[poster=first, controls, buttonsize=0.8em]{animate}

 \begin{document}
 \begin{animateinline}{10}
    \multiframe{11}{it=0+1}{
        \begin{tikzpicture}
            \begin{axis} [
                xmax = 15,
                ymax = 4,
            ]
                \addplot[domain = 0:20] coordinates {(0,0) (\it+1,0) (\it+1,1) (\it+2,1) (\it+2,0) (\it+5,0)};
            \end{axis}
        \end{tikzpicture}   
    }
 \end{animateinline}%
 \end{document}
Iam
  • 357

1 Answers1

7

Here is a proposal: Take a root of a sine curve.

\documentclass{article}
\usepackage[poster=first, controls, buttonsize=0.8em]{animate}
\usepackage{tikz}
 \tikzset{declare function={f(\x,\y)=pow(sin(180*(\x-\y)),1/(12-\y));}}
 \newcommand{\PulseOne}[1]{(0,0) --(#1,0) --
 plot[domain=#1:{#1+1},variable=\x] ({\x},{f(\x,#1)}) -- ({#1+1},0) --(12,0)}
 \begin{document}
 \begin{animateinline}{10}
 \multiframe{11}{it=0+1}{%
 \begin{tikzpicture}
  \draw[-latex](0,0)--(12.5,0) node[below]{$z$};
  \draw[blue,ultra thick] \PulseOne{\it};
 \end{tikzpicture}}
 \end{animateinline}%
 \end{document}

enter image description here

I was not sure how rapidly the squareness is supposed to disappear, but you can play with exponent in f, i.e. adjust the second argument of f. Here is an example with

\tikzset{declare function={f(\x,\y)=pow(sin(180*(\x-\y)),1/(23-2*\y));}}

enter image description here

And just for fun

\tikzset{declare function={f(\x,\y)=0.5*pow(sin(180*(\x-\y)),1/(1+(\y-11)^2));}}

enter image description here

BTW, in order to create the animated gif images, I use the code by the future Oscar winner @AlexG.