[Tex/LaTex] Draw a longitudinal wave in TikZ

tikz-pgf

I'm trying to obtain this longitudinal wave with TikZ:

enter image description here

Here's my code

\documentclass{article}
\usepackage{tikz}

\begin{document}  

\usetikzlibrary{decorations.pathmorphing}

\begin{tikzpicture}[decoration={coil}]

\draw[decorate, decoration={aspect=0.3, segment length=3mm, amplitude=3mm}] (0,0) --(3,0);
\draw[decorate, decoration={aspect=0.3, segment length=0.5mm, amplitude=3mm}] (3,0) -- (3.5,0); 
\draw[decorate, decoration={aspect=0.3, segment length=3mm, amplitude=3mm}] (3.5,0) -- (5,0);

\end{tikzpicture}
\end{document}

but so there are the junctions between one line and the others that interrupt the continuity of the coil.
How can improve it?

Best Answer

It seems that if there isn't room for a complete loop, the path will be finished with a straight line. By making a slight change in the endpoint for the first path, the result is better. Also, to make the loop continous, and not turn around at the midpoint, you can make the amplitude negative for the second and third path.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document} 

\begin{tikzpicture}[decoration={coil}]

\draw[decorate, decoration={aspect=0.3, segment length=3mm, amplitude=3mm}] (0,0) --(3.03,0);
\draw[decorate, decoration={aspect=0.3, segment length=0.5mm, amplitude=-3mm}] (3.03,0) -- (3.49,0); 
\draw[decorate, decoration={aspect=0.3, segment length=3mm, amplitude=-3mm}] (3.48,0) -- (4.98,0);

\end{tikzpicture}
\end{document}

enter image description here