1

How can I draw a spherical shell of a certain thickness using tikz?

I have found this question where somebody was asking about drawing one sphere inside another, which is surely related to this one.

Drawing Sphere to represent a black hole

Any help?

  • Welcome to TeX.SX! Can you show us what you have tried so far? (Meaning that you can add a Minimal Working Example). As you have already found the other question with nice answers, you have some starting point already - we would appreciate to see it. – Tom Jan 24 at 14:43
  • Can you also make a sketch how the result should look like? – user36296 Jan 24 at 14:50
  • I'm working on a first approximation right now so that I can show you. – Marc Jan 24 at 14:53
9

I can only guess.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
% https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}
\begin{document}
\tdplotsetmaincoords{110}{-30}
\begin{tikzpicture}[tdplot_main_coords]
\pgfmathsetmacro{\Radius}{4}
\pgfmathsetmacro{\radius}{3.6}
\path[tdplot_screen_coords] (0,0) circle (\Radius);
\begin{scope}
\clip plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=00,longitude=\x)
-- plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=90)
-- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=0)
[reverseclip];
\shade[tdplot_screen_coords,ball color=gray,opacity=0.5] (0,0) circle (\Radius);
\end{scope}
\fill[top color=gray!80,bottom color=gray!60]
plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=00,longitude=\x)
-- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=\x,longitude=90)
-- plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\radius,latitude=\x,longitude=0);
\draw[fill=gray!10] plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=00,longitude=\x)
-- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=00,longitude=\x)
-- cycle;
\draw[fill=gray!30] plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=90)
-- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=\x,longitude=90)
-- cycle;
\draw[fill=gray!70] plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=0)
-- plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\radius,latitude=\x,longitude=0)
-- cycle;
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: Just for fun (because @Raaja teased me). The code is taken from the codes that were used in the 2018 Christmas extravaganza.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
\usetikzlibrary{calc,ducks,marmots}
\usepgfmodule{nonlineartransformations}
\makeatletter
% from https://tex.stackexchange.com/a/434247/121799
\tikzdeclarecoordinatesystem{sphere}{
    \tikz@scan@one@point\relax(#1)
    \spheretransformation
}
% 
\def\spheretransformation{% similar to the pgfmanual section 103.4.2
\pgfmathsincos@{\pgf@sys@tonumber\pgf@x}%
\pgfmathsetmacro{\relX}{\the\pgf@x/28.3465}%
\pgfmathsetmacro{\relY}{\the\pgf@y/28.3465}%min(max(
\pgfmathsetmacro{\myx}{28.3465*\Radius*cos(min(max((\relY/\Radius)*(180/pi),-90),90))*sin(min(max((\relX/\Radius)*cos(min(max((\relY/\Radius)*(180/pi),-90),90))*(180/pi),-90),90))}
\pgfmathsetmacro{\myy}{28.3465*\Radius*sin(min(max((\relY/\Radius)*(180/pi),-90),90))}%\typeout{(\relX,\relY)->(\myx,\myy)}%
\pgf@x=\myx pt%
\pgf@y=\myy pt%
} 
\makeatother

\tikzfading[name=highlight,inner color=transparent!0,outer color=transparent!100]

% https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}
\begin{document}
\tdplotsetmaincoords{110}{-30}
\foreach \X in {2,1.9,...,-4}
{\begin{tikzpicture}[declare function={
myx(\x,\y,\r)=\r*cos((\y/\r)*(180/pi))*sin((\x/\r)*cos((\y/\r)*(180/pi))*(180/pi));
myy(\x,\y,\r)=\r*sin((\y/\r)*(180/pi));},tdplot_main_coords]
 \pgfmathsetmacro{\Radius}{4}
 \pgfmathsetmacro{\radius}{3.6}
 \path[tdplot_screen_coords] (0,0) circle (\Radius);
 \begin{scope}
  \clip plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=00,longitude=\x)
  -- plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=90)
  -- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=0)
  [reverseclip];
  \shade[tdplot_screen_coords,ball color=gray,opacity=0.5] (0,0) circle (\Radius);
 \end{scope}
 \draw[fill=gray!10] plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=00,longitude=\x)
 -- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=00,longitude=\x)
 -- cycle;
 \draw[fill=gray!30] plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=90)
 -- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=\x,longitude=90)
 -- cycle;
 \draw[fill=gray!70] plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\Radius,latitude=\x,longitude=0)
 -- plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\radius,latitude=\x,longitude=0)
 -- cycle;
 \clip
 plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=00,longitude=\x)
 -- plot[variable=\x,domain=90:0] (xyz spherical cs:radius=\radius,latitude=\x,longitude=90)
 -- plot[variable=\x,domain=0:90] (xyz spherical cs:radius=\radius,latitude=\x,longitude=0);
 \begin{scope}[tdplot_screen_coords]
  \shade[inner color=red, outer color=red!50!black] (0,0) circle (\radius);
  \begin{scope}[transform shape nonlinear=true]
   \pgftransformnonlinear{\spheretransformation}
   \marmot[scale=2.5,xshift=\X*1cm,yshift=-1.2cm];
  \end{scope}
  \shade[ball color=red,opacity=0.3] (0,0) circle (\radius);
  \fill[white,path fading=marmot@blush] (-.35*\radius,.5*\radius) circle (.3*\radius);
  \fill[orange!50!yellow] (0,3.9) ellipse (0.7 and 0.3);
  \draw[orange!50!yellow, ultra thick] (0.45,4.1) arc [start angle=0, end angle=180,radius=0.45];
 \end{scope}
\end{tikzpicture}}
\end{document}

enter image description here

The spurious lines do not appear on the pdf, nor on the mp4 that can be generated using this chain.

  • [off-topic] you could rotate it 180 degrees and put the Falcon in it ;) would look great – Raaja Jan 24 at 20:28
  • 1
    @Raaja still want a falcon? ;-) – user121799 Jan 24 at 23:47
  • 1
    Im working on it myself, if it doesn't work, will come back here. But the marmots gif is awesome!! – Raaja Jan 25 at 5:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.