2

Hey guys I currently don't know how to do the compression and rarefaction particle displacements. The top part of the image should be fine and I've done it in tikz but it is the bottom particle displacement section that I would like to draw using tikz (or if there's any other package made for this) but I don't know how to. Any help would be appreciated. enter image description here

1 Answer 1

4

Here is a proposal based on this answer.

\documentclass[border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{arrows.meta}
\begin{document}
    \begin{tikzpicture}[font=\sffamily]
        \begin{axis}[width=12cm,height=5cm,
            hide axis,
        ]
            \addplot [
                only marks,
                domain=0:6*pi,
                samples=1200,
                mark size=0.75,
            ] (
                {sin(deg(x+0.3*rand)) + x+0.3*rand},
                {rand}
            );
          \coordinate (max1) at ({pi},0);   
          \coordinate (max2) at ({3*pi},0);
          \coordinate (max3) at ({5*pi},0);
          \coordinate (min2) at ({2*pi},0); 
          \coordinate (min3) at ({4*pi},0); 
        \end{axis}
        \node (comp) at ([yshift=-1cm]min2 |- current axis.south) {compressions};
        \draw[-latex] (comp) -- (max1 |- current axis.south);
        \draw[-latex] (comp) -- (max2 |- current axis.south);
        \node (rare) at ([yshift=1cm]max2 |- current axis.north) {rarefactions};
        \draw[-latex] (rare) -- (min2 |- current axis.north);
        \draw[-latex] (rare) -- (min3 |- current axis.north);
        \draw[{Straight Barb[length=0pt,width=4mm] Latex[]}-{Latex[] Straight Barb[length=0pt,width=4mm]}] 
        ([yshift=-0.3cm]max2 |- current axis.south)
        --([yshift=-0.3cm]max3 |- current axis.south) 
        node[midway,fill=white]{$\lambda$};
        \draw[-latex] ([yshift=0.3cm]max3 |- current axis.north)
        -- ([yshift=0.3cm]current axis.north east)
        node[midway,above,align=center]{direction of\\ wave motion};
        \draw[latex-latex] ([xshift=0.2cm,yshift=-0.3cm]max3 |- current axis.south)
        -- ([yshift=-0.3cm]current axis.south east)
        node[midway,below,align=center]{direction of\\ particle motion};
    \end{tikzpicture}
\end{document}

enter image description here

EDIT: A pure TikZ solution with better control of the local densities.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\pgfmathsetseed{12}
\begin{tikzpicture}[font=\sffamily]
\foreach \Z in {1,...,1234}
{
 \pgfmathsetmacro{\X}{3*pi*(0.5*rand+0.5)}
 \pgfmathsetmacro{\Y}{rand}
 \pgfmathtruncatemacro{\V}{ifthenelse(1.1+0.8*sin(deg(2*\X))>1+rand,1,0)}
 \ifnum\V=1
    \fill (\X,\Y) circle (1pt);
 \fi    
}
\node[minimum width=1.5*pi*1cm,minimum height=2cm]at (3*pi,0)(current axis){};
\coordinate (max1) at ({pi/4},0);   
\coordinate (max2) at ({5*pi/4},0);
\coordinate (max3) at ({9*pi/4},0);
\coordinate (min2) at ({3*pi/4},0); 
\coordinate (min3) at ({7*pi/4},0);
\node (comp) at ([yshift=-1cm]min2 |- current axis.south) {compressions};
\draw[-latex] (comp) -- (max1 |- current axis.south);
\draw[-latex] (comp) -- (max2 |- current axis.south);
\node (rare) at ([yshift=1cm]max2 |- current axis.north) {rarefactions};
\draw[-latex] (rare) -- (min2 |- current axis.north);
\draw[-latex] (rare) -- (min3 |- current axis.north);
\draw[{Straight Barb[length=0pt,width=4mm] Latex[]}-{Latex[] Straight Barb[length=0pt,width=4mm]}] 
([yshift=-0.3cm]max2 |- current axis.south)
--([yshift=-0.3cm]max3 |- current axis.south) 
node[midway,fill=white]{$\lambda$};
\draw[-latex] ([yshift=0.3cm]max3 |- current axis.north)
-- ([yshift=0.3cm]current axis.north east)
node[midway,above,align=center]{direction of\\ wave motion};
\draw[latex-latex] ([xshift=0.2cm,yshift=-0.3cm]max3 |- current axis.south)
-- ([yshift=-0.3cm]current axis.south east)
node[midway,below,align=center]{direction of\\ particle motion};    
\end{tikzpicture}
\end{document}

enter image description here

4
  • 1
    Hello, I was wondering if it is possible to make the lack of dots in the rarefaction more pronounced, that is, can you have less dots in the rarefaction sections.
    – sab hoque
    Jul 16, 2018 at 11:55
  • @sabhoque Of course, just introduce a prefactor before sin and/or increase 0.3, i.e. try e.g. 1.2*sin(deg(x+0.4*rand)) + x+0.4*rand.
    – user121799
    Jul 16, 2018 at 11:59
  • I tried that before should I also decrease the sampling size, I'm not quite sure because the higher the amplitude on the sine function, there is no change in the density in the rarefaction sections.
    – sab hoque
    Jul 16, 2018 at 12:51
  • 1
    @sabhoque I added a pure TikZ solution with better control of the local densities. To decrease the density at the minima even further, replace \pgfmathtruncatemacro{\V}{ifthenelse(1.1+0.8*sin(deg(2*\X))>1+rand,1,0)} by \pgfmathtruncatemacro{\V}{ifthenelse(1+1*sin(deg(2*\X))>1+rand,1,0)}. If you increase the prefactor of the sine even more, there will be absolutely no points in that region.
    – user121799
    Jul 16, 2018 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .