5

How would you do a spherical rectangle? I know that for a sphere you do this:

\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}

but now I want to cut it at the edges of a rectangle like this enter image description here

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 11 '14 at 8:56
2

Like this? ![enter image description here][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}
  • how did that work for you? I get an error:! TeX capacity exceeded, sorry [input stack size=5000]. \@onefilewithoptions #1[#2][#3]#4->\@pushfilename \xdef \@currname {#1}\glob... – user60528 Aug 11 '14 at 14:17
  • somehow there were added backslashes in the code before the [ and ]. No idea how they added up there; they're not in the code I copied. – JPi Aug 11 '14 at 14:26
  • I just copied it again. – JPi Aug 11 '14 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy