带有 TikZ / PGF 图的球形矩形

带有 TikZ / PGF 图的球形矩形

你会如何画一个球形矩形?我知道对于球体你可以这样做:

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
axis equal,
colormap name=whitered,
height=20cm,
width=20cm,
view={340}{25},
axis lines = center,
ticks = none,
scale uniformly strategy=units only,
enlargelimits=0.3,
samples=20,
xlabel=$x$,
ylabel=$y$,
zlabel={$z$},
yticklabels={,,},
xticklabels={,,},
zticklabels={,,},
]

\addplot3[
surf,
shader=flat,
opacity=0.2,
fill opacity = 0.3,
samples=50, samples y=30,
domain=-1:1,y domain=0:2*pi,
z buffer=sort,
]
({sqrt(1-x^2) * cos(deg(y))},
 {sqrt(1-x^2 ) * sin(deg(y))},
  x);

\end{axis}
\end{tikzpicture}
\end{document}

但现在我想像这样沿着矩形的边缘切割 在此处输入图片描述

答案1

像这样? 在此处输入图片描述

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
axis equal,
%colormap name=whitered,
height=20cm,
width=20cm,
view={340}{25},
axis lines = none,
ticks = none,
scale uniformly strategy=units only,
enlargelimits=0.3,
samples=20,
xlabel=$x$,
ylabel=$y$,
zlabel={$z$},
yticklabels={,,},
xticklabels={,,},
zticklabels={,,},
]

\addplot3[
surf,
shader=flat,
opacity=0.2,
fill opacity = 0.3,
samples=50, samples y=30,
domain=-0.5:0.5,y domain=-0.3:0.3,
z buffer=sort,
]
%({sqrt(1-x^2) * cos(deg(y))},
% {sqrt(1-x^2 ) * sin(deg(y))},
%  x);
(x,y,{sqrt(1-x^2-y^2)});
\end{axis}
\end{tikzpicture}
\end{document}

相关内容