我正在尝试使用 TIKZ 在 3D 中绘制参数曲线,我希望当曲线与自身重叠时会留下一条白色轨迹来显示可见的部分,(如下图左所示)。但为了得到它,我不得不把路径分成几部分,当我尝试用一个命令绘制它时,它不起作用(右图)。
不打破路径是否可以达到同样的效果?在这个图中,我找到的解决方案已经足够好了,但在其他图中,找出如何打破路径要困难得多,而且耗时得多。
以下是代码:
\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}
答案1
\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}