我正在使用 addplot3 创建一个曲面,但我希望突出显示曲面上的特定点曲线。不是像水平集曲线那样简单。因此,部分曲线应该隐藏在曲面后面,但我认为如果不将曲线实际分解为应该在曲面后面的部分和应该在曲面前面的部分,就无法做到这一点。
这是目前为止我能做的最好的事情,但并不正确,因为螺旋永远在前面。
\documentclass[border=15pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps,fillbetween}
\begin{document}
\pgfplotsset{compat=1.10,
colormap/red/.style={
colormap={red}{
rgb=(1.0, 0.0, 0.0)
rgb=(1.0, 0.0, 0.0)
}
}
}
\begin{tikzpicture}
\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}
\begin{axis}[
hide axis,
colormap/bone,
view={25}{20}
]
\addplot3 [surf,
colormap/bone, %colour scheme
domain=0*pi:4*pi, %sets range for x
y domain=0:4*pi, %sets range for y
samples=50, %number of samples taken
z buffer=sort]
(
{cos(\x r)},
{sin(\x r)},
{\y}
);
\addplot3 [surf,
colormap/red, %colour scheme
domain=0*pi:4*pi, %sets range for x
y domain=0:4*pi, %sets range for y
samples=50, %number of samples taken
z buffer=sort]
(
{cos(\x r)},
{sin(\x r)},
{\x}
);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您需要按适当的顺序绘制图的各个部分。此解决方案假设方位角(即的第二个参数view={25}{20}
)为正。(我也更喜欢径向角,但 pgfplots 内部使用度数,所以我改用了。)顺便说一句,要绘制红色曲线,您不需要表面图,但您可以使用samples y=1
。
\documentclass[border=15pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\begin{document}
\pgfplotsset{compat=1.17}
\begin{tikzpicture}
\begin{axis}[
hide axis,
colormap/bone,
view={25}{20}]
\addplot3 [surf,
colormap/bone, %colour scheme
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180, %sets range for x
y domain=0:4*pi, %sets range for y
samples=25, %number of samples taken
z buffer=sort]
(
{cos(\x)},
{sin(\x)},
{\y}
);
\pgfplotsinvokeforeach{0,360}{%
\addplot3 [red,thick,
domain=#1+\pgfkeysvalueof{/pgfplots/view/az}:#1+\pgfkeysvalueof{/pgfplots/view/az}+180, %sets range for x
samples=25, %number of samples taken
samples y=1]
(
{cos(\x)},
{sin(\x)},
{\x*pi/180}
);
}
\addplot3 [surf,
colormap/bone, %colour scheme
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180, %sets range for x
y domain=0:4*pi, %sets range for y
samples=25, %number of samples taken
z buffer=sort]
(
{cos(\x)},
{sin(\x)},
{\y}
);
\pgfplotsinvokeforeach{0:\pgfkeysvalueof{/pgfplots/view/az},%
\pgfkeysvalueof{/pgfplots/view/az}+180:\pgfkeysvalueof{/pgfplots/view/az}+360,%
\pgfkeysvalueof{/pgfplots/view/az}+540:720}{%
\addplot3 [red,thick,
domain=#1, %sets range for x
samples=25, %number of samples taken
samples y=1]
(
{cos(\x)},
{sin(\x)},
{\x*pi/180}
);
}
\end{axis}
\end{tikzpicture}
\end{document}