最初我得到的是类似这样的结果,其中有一个半球,下面是梯度场。但我无法让边缘一直向下并环视四周。我总是遇到计算问题,而且总是被困在一个八分圆上。
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
view={-30}{-20},
domain=0.001:0.7,
y domain=0.001:0.7,
samples=20
]
\addplot3[blue,/pgfplots/quiver,
quiver/u=-x/(-x^2-y^2+1)^(-1/2),
quiver/v=-y/(-x^2-y^2+1)^(-1/2),
quiver/w=0,
quiver/scale arrows=0.2,
-stealth,samples=10] {0};
\addplot3[surf,opacity=0.3] {(1-x^2-y^2)^(1/2)};
\end{axis}
\end{tikzpicture}
\end{document}
理想情况下,我想使输出像这个 geogebra 小程序一样:https://www.geogebra.org/m/QhfcuhqA(我可以在其中绘制表面以及绘制下面的梯度场)我的目标是与这个半球进行某种合并,下面是梯度场。如果我可以只输入圆锥或双曲抛物面的函数,它就会给我表面下面的梯度场,那将是一个梦想,但如果手动完成也可以。
\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[ samples=50,domain=0:360,y domain=0:90,
xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2,zmin=0,zmax=1.2]
\addplot3[surf,opacity=0.3]
({cos(x)*cos(y)}, {sin(x)*cos(y)}, {sin(y)});
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
view={-30}{-20},
domain=0.001:0.7,
y domain=0.001:0.7,
samples=20
]
\addplot3[blue,/pgfplots/quiver,
quiver/u=-x/(-x^2-y^2+1)^(-1/2),
quiver/v=-y/(-x^2-y^2+1)^(-1/2),
quiver/w=0,
quiver/scale arrows=0.2,
-stealth,samples=10] {0};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis} [xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2,zmin=0,zmax=1.2]
\addplot3[surf,opacity=0.3, samples=50,domain=0:360,y domain=0:90]
({cos(x)*cos(y)}, {sin(x)*cos(y)}, {sin(y)});
\addplot3[blue,
domain=-1:1, y domain=-1:1,
unbounded coords=discard,
samples=21,
quiver={every arrow/.append style={-{Latex[length=1.5pt]}}},
quiver/u=-x/(-x^2-y^2+1)^(-1/2),
quiver/v=-y/(-x^2-y^2+1)^(-1/2),
quiver/w=0,
quiver/scale arrows=0.2,
x filter/.expression={(-x^2-y^2+1)>0?x:nan},
y filter/.expression={(-x^2-y^2+1)>0?y:nan},
x filter/.expression={x==0&&y==0?nan:x},
] {0};
\end{axis}
\end{tikzpicture}
\end{document}