# TikZ path decorated with coil or snake

A recurrent question on the forum is... How to draw a decorated path without a straight segment at the end?

Usually the path described are straight lines (See post1, post2 or post3), but there are also solutions for semi circle paths (see post4).

I'm interested in drawing a general path, decorated with a coil and a snake (with an entire number of wave length). I found an interesting solution for snake decoration HERE, however, no clue for coil decoration is given.

Question

How could a general path be decorated with a coil? constrained to have an entire number of wave length.

## Update

It has been pointed out by percusse different problems in the definition of my question. So, I'll be less aggressive...

Question v.2.0

Assume that we have a sufficiently smooth path (without vertices or abrupt changes). Additionally, we want the end-points of the path to be centred on the amplitude of the coil. If possible, instead of giving a "wave length" for the coil, we'd like to control the number of turns.

How would such a construction be defined?

• The difficulty with coming up with a solution for arbitrary paths is due to the ambiguity of the spec. What should happen if there is a corner on the path, what should happen if the length is shorter than the unit coil etc. If there are arbitrary curves or else should it change with the angle or should the coils deform too? You need more details to specify the behavior. – percusse Oct 28 '13 at 15:17
• Have you looked at the path decoration macros in feynmp.mp? The curly macro shows how to decorate a path with coils in Metapost without adding initial or final straight sections. Might that provide a starting point for PGF? – Thruston Mar 7 '14 at 9:32

Here is one idea that don't work very well (because of the precision problems).

1. Take the length of the path
2. set the coil segment length ot 1/n of this length and decorate ...

Here is one experimentation.

\documentclass[varwidth,border=7mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings,decorations.pathmorphing}
\tikzset{
get length/.style = {
preaction={decorate,
decoration={ markings,
mark = at position 1 with
{
\pgfkeysgetvalue{/pgf/decoration/mark info/distance from start}{\len}
\xdef\pathlen{\len}
}
}
}
}
}

\begin{document}
\begin{tikzpicture}
\draw [get length] (0,0) circle(3);
\draw[decoration={coil,amplitude=3mm,segment length={\pathlen /200}},
decorate] (0,0) circle(3);
\end{tikzpicture}
\end{document} 