Hi everybody I was trying to draw a spiral coiled tube
with TikZ decoration library. This is what i got so far:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{example}{initial} {
\state{initial}[width=5mm, next state=mynext] {
%
\pgfpathmoveto{\pgfpoint{0cm }{1cm }}
\pgfpathquadraticcurveto{\pgfpoint{.6cm }{.5cm }}{\pgfpoint{0cm }{0cm }}
\pgfpathquadraticcurveto{\pgfpoint{.25cm }{.1cm }}{\pgfpoint{.5cm }{0cm }}
\pgfpathquadraticcurveto{\pgfpoint{1.2cm }{.5cm }}{\pgfpoint{.5cm }{1cm }}
\pgfpathquadraticcurveto{\pgfpoint{.25cm }{.9cm }}{\pgfpoint{0cm}{1cm}}
\pgfpathmoveto{\pgfpoint{.5cm }{0cm }}
}
\state{mynext}[width=5mm]{
\pgfpathquadraticcurveto{\pgfpoint{.25cm }{.1cm }}{\pgfpoint{.5cm }{0cm }}\pgfpathquadraticcurveto{\pgfpoint{1.2cm }{.5cm }}{\pgfpoint{.5cm }{1cm }}
\pgfpathquadraticcurveto{\pgfpoint{.25cm }{.9cm }}{\pgfpoint{0cm}{1cm}}
\pgfpathmoveto{\pgfpoint{.5cm }{0cm }}
}
\state{final} {
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\begin{document}
\tikz[decoration=example] {
\draw [decorate] (0,0) -- (3,0);
\draw [blue!20!,decorate] (0,0) to [out=45,in=135] (3,0);
\draw [red,decorate] (0,-5) to [out=30,in=100] (3,-5);
}
\end{document}
This results in a good one for straight lines, but with some bending there is a gap between the segments. So this is what i expected since i'am not able to hand over two coordinates to the next repetition.
I tried to compute the end point (upper corner) by storing \pgfdecoratedangle
and transforming it back to the last segments angel but \pgfdecoratedangle
seems to be empty.
So how can i connect those segments properly and/or how could one draw such a tube ?
Update: another approach with an existing decorations:
\documentclass[border=1mm]{standalone}
% based on http://tex.stackexchange.com/questions/31707/how-to-raise-a-generic-curve-problem-with-pgfdeclaredecoration
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{forcedist/.style={decorate, decoration={markings,
mark=between positions 0 and 1 step 0.0999 with {\draw[thick] (0,-#1) to[bend left] (0,#1); }}}}
\begin{document}
\begin{tikzpicture}
\draw [double distance = 1cm,thick, double=red, decoration=snake] (0,0) .. controls++(1,1) and (6,-3).. (7,0);
% those lines should be wavy
\draw [forcedist=5mm] (0,0) .. controls++(1,1) and (6,-3).. (7,0);
\draw [double distance = 5mm,thick, double=red] (0,3) --++(8,0);
\draw [forcedist=2.5mm ] (0,3)--++(8,0);
\end{tikzpicture}
\end{document}
So this looks quite encouraging, although i'm not able to make those douled lines wavy so that there is a impression of a thicker spiral. The latter results in
\pgfdecoratedangle
does indeed not work, strangely enough. Nevertheless you should post the code you tried. I guess you wanted to use thepersistent pre/postcomputation
options. Another approach would be to do something like this: tex.stackexchange.com/questions/31707/…persistent precomputation
how can i store a point in such a way that i can refer on it after the transformation?