# How to get a tangent coordinate system for the decoration of a path?

I want to draw some lines in a tangent coordinate system of the decoration of a path. Especially I want to draw a tangent segment at the end of the decoration with full controll, i.e. with having the start end end points of the segment as coordinates.

I tried the following (adapted from an answer to How to draw tangent line of an arbitrary point on a path in TikZ):

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[tangent/.style={
decoration={
markings,% switch on markings
mark=
at position #1
with
{
\coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
\coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
\coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
}
},
postaction=decorate
},
use tangent/.style={
shift=(tangent point-#1),
x=(tangent unit vector-#1),
y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1]

\draw[decorate,tangent=0,decoration={coil,amplitude=20,segment length=20,post length=0}] (0,0) coordinate (X) -- ++(5,5);

\node[below] at (X) {$x$};
%want a tangent line at (X) with start end end coordinates
\draw[use tangent] (0,0) -- ++(1,0);

\end{tikzpicture}
\end{document}


However I get an error:

ERROR: Package pgf Error: No shape named tangent unit vector-1 is known.

Output of the imcomplete picture:

Any idea how to make this work? I guess that there should be a more easy way to do it.

I think one can't use two decorations at once on the same path.

To be more specific to your question :

\tikzset{%
tangent/.style args={#1 at #2}{%
decoration={%
markings,% switch on markings
% can not not work at 0 exactly for obvious resons
mark=at position #2 with {#1}},
postaction={decorate}
}
}


And the tangent it self, or what ever you want :

\draw[use path=bob,tangent={%
{
% what ever you want, as if you were in a scope
\draw[blue,thick,->,>=stealth] (0,0)--(1,0) ;
} at .0001}] ;
\node[below] at (X) {$x$};
\end{tikzpicture}


\documentclass[tikz]{standalone}
\usepackage[active,tightpage]{preview}

\usetikzlibrary{decorations.markings,decorations.pathmorphing,intersections}

%%%%                        ---- Use path several times
%%%%                        ---- thanks to Andrew Stacey
\makeatletter
\tikzset{
use path for main/.code={%
\expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
}%
},
use path for actions/.code={%
\expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
},
use path/.style={%
use path for main=#1,
use path for actions=#1,
}
}

\tikzset{%
tangent/.style args={#1 per #2 at #3}{%
decoration={%
markings,% switch on markings
% can not not work at 0 exactly for obvious resons
mark=at position #3 with {\draw[red] (#2,0)--(0,0)--(0,#1) ;}
},
postaction={decorate}
}
}

\begin{document}

\foreach \x in {0.0001,.01,0.02,...,1} {%
\begin{preview}
\begin{tikzpicture}

\draw (-1.5,-.5) rectangle (5.5,5.5) ;

\path [decorate,decoration={coil,amplitude=20,segment length=20,post length=0},name path=bob]   (0,0) coordinate (X) -- ++(5,5);

\draw[use path=bob,tangent={.5 per .7 at \x}] ;
\node[below] at (X) {$x$};
\end{tikzpicture}
\end{preview}}

\end{document}