# Tikz draw a parametric curve in 3D with border

I am trying to draw parametric curves in 3D using TIKZ, I would like that when the curve overlaps itself it leaves a white trail to show the visible part, (as it is shown in the left figure below). But to obtain it I had to break the path in pieces, when I try to draw it in a single command it doesn't work (right figure).

Is it possible to obtain the same effect without breaking the path? In this plot the solution I found is good enough but in other plots it is a lot more difficult and time consuming to figure out how to break the path.

Here is the code:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
%left figure
\draw[domain=0:360,smooth,variable=\t,white,very thick,double=black]
plot({sin(\t)},\t/360,{cos(\t)});
\draw[domain=360:720,smooth,variable=\t,white,very thick,double=black]
plot({sin(\t)},\t/360,{cos(\t)});
\draw[domain=720:900,smooth,variable=\t,white,very thick,double=black]
plot({sin(\t)},\t/360,{cos(\t)});

%right figure
\begin{scope}[shift={(3,0)}]
\draw[domain=0:900,smooth,variable=\t,white,very thick,double=black]
plot({sin(\t)},\t/360,{cos(\t)});
\end{scope}
\end{tikzpicture}


This question is almost identical to this one, so one can just the corresponding answer.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[rubout/.style={/utils/exec=\tikzset{rubout/.cd,#1},
decoration={show path construction,
curveto code={
\draw [white,line width=\pgfkeysvalueof{/tikz/rubout/line width}+2*\pgfkeysvalueof{/tikz/rubout/halo}]
(\tikzinputsegmentfirst) .. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)  ..(\tikzinputsegmentlast);
\draw [line width=\pgfkeysvalueof{/tikz/rubout/line width},shorten <=-0.1pt,shorten >=-0.1pt] (\tikzinputsegmentfirst) .. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast);
}}},rubout/.cd,line width/.initial=2pt,halo/.initial=0.5pt]
\draw[rubout={line width=1pt,halo=1.2pt},decorate,
domain=0:900,samples=101,smooth,variable=\t]
plot({sin(\t)},\t/360,{cos(\t)});
\end{tikzpicture}
\end{document}


• Thank you very much. It is what I was looking for, I had missed the original question. Apr 23, 2021 at 19:12
• Very interesting solution. But when it comes to bigger line width, some scratches appear. Even on the drawing above you can see a fine line at the intersections. This is caused by the fact that the white line is discontinuous (it's very easy to see it by changing its color to something visible). I wonder if there could be a way to make this rubber continuous. Apr 23, 2021 at 21:32
• @SebGlav What happens here is that single stretches, including their halo, get drawn successively. As you say, for certain combinations of the number of stretches, which corresponds loosely to the number of samples in the above code, the result may not be good. Often this problem can be solved by adjusting the number of samples, but probably there are cases where the fix is not so simple. Probably the knots library is a more powerful and general approach in more complex scenarios.
– user240002
Apr 23, 2021 at 21:48