TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

enter image description here

Here's my code





\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);


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

share|improve this question
up vote 14 down vote accepted

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.



\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);


enter image description here

share|improve this answer
wow! thank you! the solution was simpler than I thought! – Ale Jun 11 '11 at 15:49

Here's an alternative to using decorations which gives you a little more control (though I should say at the outset that I think that the more stylised version from the decoration actually looks neater). I recently found myself wanting to draw a helix and so adapted the code for arcs to allow for a transversal shift as it draws the arc. By varying the shift, I can get a longitudinal wave. The code looks a bit complicated, but it is a very simple adaptation of the code for arcs (and of course it could be hidden away in a package!).

Here's the result first:

longitudinal wave

If the horrible code were in a package, this is what you would write to get that:

\foreach \sep in {0,10,...,360} {
   start angle=90,
   delta angle=360,
\pgfmathsetmacro{\gxhelix}{\xhelix + \gxhelix}

The helix key replaces the arc macro with the modified one and sets the shift factor in the helix. So by varying that, we can get the wave-like behaviour. The \helical macro is a shortcut for computing the shift factor so that each cycle starts at the right place from the previous.

The horrible code is the following:


% convert an angle into a helical distance

  \pgfutil@tempdima=\pgf@arc@radius@a pt%
  \pgfutil@tempdimb=\pgf@arc@radius@b pt%
  \advance\pgf@xb by-\pgf@xa\relax%
    \pgfmathparse{1.333333333*tan(.25*\pgf@sys@tonumber{\pgf@xb})}% many thanks to Ken Starks
  %.. controls +(\pgf@xa+90:\pgfutil@tempdima) and +(\pgf@xb-90:\pgfutil@tempdima) .. +(-(#1:#3)+(#2:#3))%
  % store first support vector in xa/ya:
    \advance\pgf@xa by 90pt\relax%
    \advance\pgf@xa by -90pt\relax%
  \pgfpointtransformed{\pgfpointpolar{\pgf@arc@angle}{\pgfutil@tempdima and \pgfutil@tempdimb}}%
  \advance\pgf@x by-\pgf@pt@x%
  \advance\pgf@y by-\pgf@pt@y%
  \advance\pgf@xa by \pgf@x%
  \advance\pgf@ya by \pgf@y%
  % store target in xb/yb:
  \pgfpointtransformed{\pgfpointpolar{\pgf@sys@tonumber{\pgf@arc@local@angle@a}}{\pgf@arc@radius@a pt and \pgf@arc@radius@b pt}}%
  \advance\pgf@xb by -\pgf@x%
  \advance\pgf@yb by -\pgf@y%
  \pgfpointtransformed{\pgfpointpolar{\pgf@sys@tonumber{\pgf@arc@local@angle@b}}{\pgf@arc@radius@a pt and \pgf@arc@radius@b pt}}%
  \advance\pgf@xb by \pgf@x%
  \advance\pgf@yb by \pgf@y%
  % store second support xc/yc:
    \advance\pgf@arc@local@angle@b by -90pt\relax%
    \advance\pgf@arc@local@angle@b by 90pt\relax%
  \pgfpointtransformed{\pgfpointpolar{\pgf@sys@tonumber{\pgf@arc@local@angle@b}}{\pgfutil@tempdima and \pgfutil@tempdimb}}%
  \advance\pgf@x by-\pgf@pt@x%
  \advance\pgf@y by-\pgf@pt@y%
  \advance \pgf@xc by \pgf@x\relax%
  \advance \pgf@yc by \pgf@y\relax%
    \advance\pgf@xa by .3333333\pgf@helix@len\relax
    \advance\pgf@xc by .6666666\pgf@helix@len\relax
    \advance\pgf@xb by \pgf@helix@len\relax
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.