我目前有这个 3D 图,我想展示线积分基本定理,只需找到端点即可。使用surf
,我能够得到我想要的形状,但我希望它在向下时为红色,向上时为蓝色。我尝试使用黑色,但它会创建一条连接端点的线。
我怎样才能分割表面上的曲线?
\documentclass[aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz, tikz-3dplot, pgfplots}
\pgfplotsset{width=7cm,compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis} [xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2,zmin=0,zmax=1.2,view={45}{30}]
\addplot3 [surf, opacity=0.1, samples=20, z buffer=sort, domain=0:360, y domain=0:1] ({cos(x)*y},{sin(x)*y},
{sqrt(1-(cos(x)*y)^2-(sin(x)*y)^2))});
\foreach \posx/\posy in { 0.3/-0.4}{
\addplot3 [surf, ultra thick, domain=0:200, samples=20] (
{cos(x)*0.4+\posx},
{sin(x)*0.4+\posy},
{sqrt(1-((cos(x)*0.4+\posx))^2-((sin(x)*0.4+\posy))^2))}
);
}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-1.2, xmax=1.2,
ymin=-1.2, ymax=1.2,
zmin=0, zmax=1.2,
view={45}{30},
]
\addplot3[surf, opacity=0.1, samples=20, z buffer=sort, domain=0:360, y domain=0:1] ({cos(x)*y},{sin(x)*y}, {sqrt(1-(cos(x)*y)^2-(sin(x)*y)^2))});
\addplot3[red, ultra thick, domain=130:200, samples=20, samples y=1] ( {cos(x)*0.4+0.3}, {sin(x)*0.4-0.4}, {sqrt(1-((cos(x)*0.4+0.3))^2-((sin(x)*0.4-0.4))^2))} );
\addplot3[blue, ultra thick, domain=0:130, samples=20, samples y=1] ( {cos(x)*0.4+0.3}, {sin(x)*0.4-0.4}, {sqrt(1-((cos(x)*0.4+0.3))^2-((sin(x)*0.4-0.4))^2))} );
\end{axis}
\end{tikzpicture}
\end{document}