Is it possible to define a decoration/postaction, for drawing a double line so that a self intersecting line will draw on top of itself? To show what I mean see these spirals:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[red, double=yellow, thick, domain=0:pi, smooth, samples=200] plot (\x, {cos(10*\x r)} , {sin(10*\x r)} );
\begin{scope}[yshift=-3cm]
\foreach \i in {1,...,10}
\draw[red, double=yellow, thick, domain=pi*(\i-1)/10:pi*\i/10, smooth, samples=200] plot (\x, {cos(10*\x r)} , {sin(10*\x r)} );
\end{scope}
\end{tikzpicture}
\end{document}
The top spiral shows the effect of a normal double line and the bottom spiral shows the desired result. I wish the result done with just one \draw command to avoid rendering artefacts and make the smooth option work across the whole spiral.
Ultimately, I want to be able to use white as the outer color and thereby creating a crossing effect. To be able to better answer questions on this site e.g. Conical and cylindircal spirals
I was thinking that it should be possible by making the double on small segments of the path as it is being drawn. A naive approach like this:
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary {decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw[yellow,
decorate, decoration={zigzag, segment length=1mm, amplitude=0mm},
preaction={draw, ultra thick, red},
domain=0:pi, samples=200] plot (\x, {cos(10*\x r)} , {sin(10*\x r)} );
\end{tikzpicture}
\end{document}
does not work as the preaction is applied to the whole path and not the segments.
A even better solution would be if the path could clip itself, so that the crossing would look nice on a non-white background. - Probably quite complicated.



shorten!? – hpekristiansen Nov 28 '20 at 17:18shorten <=-0.002 ptmakes it better – hpekristiansen Nov 28 '20 at 17:28knotslibrary. However, I am not sure if this is ideal for the scenario you want to use it on. IMHO the 3d coil from the linked answer might be a reasonable alternative. (I also tried to shorten the stretches by a negative amount but the result does not look fully convincing on all viewers I tried.) – Nov 28 '20 at 17:29\draw[red, double=yellow,with\path[. -so that it is not drawn twice. I am not sure that it does anything. – hpekristiansen Nov 28 '20 at 17:53smoothoption, it is very visible that the line segments are not mitred. In the same way will individual curved segments not end in the exact same angle as the next curve segment starts. Conclusion: The artefacts are real and not just viewer rendering. – hpekristiansen Nov 28 '20 at 18:04acroreadandpreview. – Nov 28 '20 at 18:07samples=200, which produces 199 plot segments, each of which is a Bezier curve since you use thesmoothkey. That is, the segment length is entirely specified by the path you decorate. – Nov 28 '20 at 18:16