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. 
Asked
Active
Viewed 350 times
2
sab hoque
- 2,627
1 Answers
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}
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}


sinand/or increase0.3, i.e. try e.g.1.2*sin(deg(x+0.4*rand)) + x+0.4*rand. – Jul 16 '18 at 11:59\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. – Jul 16 '18 at 12:57