32

Can anybody tell me how to draw up a sphere inside a sphere?

What I mean is something like this:

enter image description here

Also where it says the different horizons be able to insert a mathematical expression? Also not in these poor colours something that looks kind of professional.

Any help much appreciated.

2

3 Answers 3

40

This can be done quite easily with TikZ, although you will have to think about the order you put the commands. In nodes you can use math mode:

Code

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}
    \fill (-4,-4)   rectangle (4,4);
    \begin{scope}
        \clip (0:2.47) arc (0:90:2.47) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.47);
        \shade[ball color=blue!30!gray!60!black,shading angle=180] (0,0) circle (2.5);
    \end{scope}
    \shade[ball color=green!70!gray] (0,0) circle (2);
    \begin{scope}
        \clip (0:1.95) arc (0:90:1.95) to[out=225,in=100] (-0.7,-0.7) to[out=-10,in=225] (0:1.95);
        \shade[ball color=green!30!gray!60!black,,shading angle=180] (0,0) circle (2);
    \end{scope}
    \begin{scope}
        \clip (0:2.45) arc (0:90:2.45) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.45) -- (3,0) -- (3,-3) -- (-3,-3) -- (-3,3) -- (3,3) -- (3,0);
        \shade[ball color=blue!70!gray] (0,0) circle (2.5);
    \end{scope}
    \draw[stealth-,red] (0,0) -- ++(70:3) node[right] {$r=\int\limits_{0}^{2\pi}\sin(x)\ dx$};
    \draw[stealth-,green!70!black] (-0.7,1) -- ++(135:2) node[above] {$r=\frac{8^2+4^2}{8^2+6^2}$};
    \draw[stealth-,blue!90] (225:2) -- ++(225:1) node[below] {$r=\left(\frac{e^{\pi}}{\pi^e}\right)^{\sin(\pi)}$};
\end{tikzpicture}

\end{document}

Output

enter image description here


Edit 1:

To make the spheres look less glossy, you can define your own radial shading, or modify the ball shading (thanks to Yori for this answer)

Code

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows}

\makeatletter
\pgfdeclareradialshading[tikz@ball]{ball}{\pgfqpoint{-10bp}{10bp}}%
{   color(0bp)=(tikz@ball!50!white);
    color(10bp)=(tikz@ball!75!white);
    color(15bp)=(tikz@ball);
    color(20bp)=(tikz@ball!75!black);
    color(30bp)=(tikz@ball!50!black)
}
\makeatother

\begin{document}

\begin{tikzpicture}
    \fill (-4,-4)   rectangle (4,4);
    \begin{scope}
        \clip (0:2.47) arc (0:90:2.47) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.47);
        \shade[ball color=blue!30!gray!60!black,shading angle=180] (0,0) circle (2.5);
    \end{scope}
    \shade[ball color=green!70!gray] (0,0) circle (2);
    \begin{scope}
        \clip (0:1.95) arc (0:90:1.95) to[out=225,in=100] (-0.7,-0.7) to[out=-10,in=225] (0:1.95);
        \shade[ball color=green!30!gray!60!black,shading angle=180] (0,0) circle (2);
    \end{scope}
    \begin{scope}
        \clip (0:2.45) arc (0:90:2.45) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.45) -- (3,0) -- (3,-3) -- (-3,-3) -- (-3,3) -- (3,3) -- (3,0);
        \shade[ball color=blue!70!gray,opacity=0.90] (0,0) circle (2.5);
    \end{scope}
    \draw[stealth-,red] (0,0) -- ++(70:3) node[right] {$r=\int\limits_{0}^{2\pi}\sin(x)\ dx$};
    \draw[stealth-,green!70!black] (-0.7,1) -- ++(135:2) node[above] {$r=\frac{8^2+4^2}{8^2+6^2}$};
    \draw[stealth-,blue!90] (225:2.2) -- ++(225:1) node[below] {$r=\left(\frac{e^{\pi}}{\pi^e}\right)^{\sin(\pi)}$};
\end{tikzpicture}

\end{document}

Output

enter image description here

5
  • 1
    That is absolutely amazing thanks a million for the quick reply.
    – LatexNoob
    Oct 19, 2013 at 12:41
  • 1 last thing here absolutely rookie at this stuff but how do you keep the background white ?
    – LatexNoob
    Oct 19, 2013 at 12:52
  • O never mind was messing around with it it was almost the first line Thanks again :D
    – LatexNoob
    Oct 19, 2013 at 13:04
  • Yeah, fill with no color specification means black. I'll remember to not silently use this. Oct 19, 2013 at 15:01
  • I just came to upvote. Nothing less nothing more.
    – Diaa
    Aug 27, 2016 at 21:24
23

Quite similar in spirit to Tim Bombadil's more complete answer, but using a slightly different approach so the order of drawing is easier to manage. It only currently works for the "opening" with 90 degree arcs along the relevant axes as they are approximated with Bézier curves.

\documentclass[border=0cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}

% Constant taken from
%
% @article{riskus_2006,
%   author={Aleksas Ri\v{s}kus},
%   title={Approximation of a cubic bezier curve by circular arcs and vice versa},
%   year={2006},
%   journal={Information Technology and Control},
%   volume={35},
%   number={4},
%   pages={371--378}
% }
%
\def\k{0.55191496}

\tikzset{
    sphere color/.store in=\spherecolor,
    sphere scale/.store in=\spherescale,
    sphere color=blue,
    sphere scale=1,
    sphere/.style={
        ultra thick,
        line join=round,
        draw=#1!75!black,
        ball color=#1,
    },
    sphere inside/.style={
        shading angle=180,
        sphere=#1!25!gray!75!black
    }
}

\newenvironment{sphere}[1][]
    {
        \begin{scope}[x=(0:1cm), y=(90:1cm), z=(260:0.25cm), #1]
            \path [sphere inside=\spherecolor, scale=\spherescale] 
            circle [radius=1];
    }
    {
        \path let \n1={cos 10}, \n2={sin 10} in [sphere=\spherecolor, scale=\spherescale, even odd rule, opacity=0.5]
        circle [radius=1] 
        % Rotate 10 degrees around the y and x axes
        [x={(\n1, \n2^2, \n2*\n1)},
         y={(0, \n1, \n2)}, 
         z={(-\n2, -\n1*\n2, \n1^2)}] (0,1,0) 
                .. controls ++( 0, 0,\k) and ++(0,\k, 0) .. (0, 0, 1)
                .. controls ++(\k, 0, 0) and ++(0, 0,\k) .. (1, 0, 0) 
                .. controls ++(0, \k, 0) and ++(\k,0, 0) .. (0, 1, 0);
        \end{scope}
    }

\begin{document}

\begin{tikzpicture}[background rectangle/.style={fill=black}, show background rectangle]

\begin{sphere}[sphere scale=5, sphere color=blue]
    \begin{sphere}[sphere scale=4, sphere color=green]
        \begin{sphere}[sphere scale=3, sphere color=red]
            \begin{sphere}[sphere scale=2, sphere color=orange]
                \begin{sphere}[sphere scale=1, sphere color=yellow]

                \end{sphere}
            \end{sphere}
        \end{sphere}
    \end{sphere}
\end{sphere}

\end{tikzpicture}

\end{document}

enter image description here

3
  • Beautiful!!!!!!!!!!!!!!!!!! Oct 19, 2013 at 16:45
  • Very nice! That reminds me a lot of an old painting, where one man is looking out in the sevweral shells of which the sky consists. Don't remember the title or artist though, it drives me crazy ;D Oct 19, 2013 at 22:25
  • That is amazing well done you and the rest of the people on this have serious skills.
    – LatexNoob
    Oct 30, 2013 at 22:08
13

ePiX is a col­lec­tion of batch-ori­ented util­i­ties for GNU/Linux sys­tems, creates mathematically accurate figures, plots, and movies with output format(PSTricks, tikz, or eepic macros) or as vector (EPS or PDF) image files for use with LaTeX, Unfortunately not available on traditional TeXLive/MiKTeX distro but can be installed on Linux distro (Ubuntu) with sudo apt-get install epix.

This drawing can be done in ePiX, if you don't mind using an external image file. (The coordinate grids in the compiled PDF aren't as prominent as in the png file below.)

Output

black hole horizons

Code

 /* -*-ePiX-*- */
    #include "epix.h"
    using namespace ePiX;

    double rad1(1), rad2(0.75);

    int N(60); // fineness of plot

    // parameter domains for southern/northern portions
    domain lower(P(0, 0, -M_PI_2), P(1, 2*M_PI, 0), mesh(N, N, 0.25*N));
    domain upper(P(0, M_PI_2, 0), P(1, 2*M_PI, M_PI_2), mesh(N, 0.75*N, 0.25*N));

    int main()
    {
      picture(P(-2,-2), P(2,2), "3 x 3in");

      begin();
      camera.at(P(4, 2, 2));

      fill();
      green(0.6);
      scenery S(sph, lower.slice1(rad2));
      S.add(sph, upper.slice1(rad2));

      // add slightly smaller sphere in brighter shade
      double scale(0.99);
      green(1.2);
      S.add(sph, lower.slice1(scale*rad2));
      S.add(sph, upper.slice1(scale*rad2));

      blue(0.8);
      S.add(sph, lower.slice1(rad1));
      S.add(sph, upper.slice1(rad1));

      blue(1.2);
      S.add(sph, lower.slice1(scale*rad1));
      S.add(sph, upper.slice1(scale*rad1));

      S.draw();

      // labels and guide lines
      black();
      P O(0, 0, 0),
        lbl1(sph(1.1*rad1, -M_PI_4, M_PI_4)),
        lbl2(sph(1.2*rad1, -M_PI/8, 5*M_PI/12)),
        lbl2b(sph(rad2, 0, 5*M_PI/12)),
        lbl3(sph(1.2*rad1, M_PI_2, M_PI/3));

      label(lbl1, P(-2, 2), "Outer horizon", tl);
      label(lbl2, P(-2, 2), "Inner horizon", t);
      label(lbl3, P(-2, 2), "Singularity", tr);

      pen(White(), 2);
      line(lbl2, lbl2b);
      line(lbl3, O);

      pen(Black(), 1);
      line(lbl2, lbl2b);
      line(lbl3, O);

      red();
      dot(P(0, 0, 0));

      tikz_format();
      end();
    }

Compilation methods

a)Running ePiX via command line: (Needs an TeXLive distro installed along with ePiX for conversion to pdf)

  • Save example code as sphereblack.xp and run at command line elaps --pdf sphereblack.xp generates sphereblack.pdf directly to include in LaTeX separately.

b)Running ePiX inside .tex file :

% pdflatex -shell-escape sphere.tex
\documentclass{article}
\immediate\write18{epix sphereblack.xp} % tikz macros due to tikz_format();
\usepackage{tikz}
\begin{document}
\input{sphereblack.eepic} % Input the tikz macros in sphereblack.eepic
\end{document}

For more detailed information on refer ePiX manual

3
  • 3
    While we are happy to learn new ways of drawing, it will be appreciated if you include the details of how to compile the above code. Also is it possible to embed this code inside a tex file? (like we can do with asy files).
    – user11232
    Oct 19, 2013 at 1:19
  • 1
    @HarishKumar Updated some details on installing/running/(embedding in TeX) ePiX on Linux. Oct 19, 2013 at 4:36
  • @texenthusiast: Thank you for the additional details! :) (Tangentially and at risk of stating the obvious, I don't recommend compiling figures from within a "live" document. The eepic file of the black hole figure above takes about 20 seconds to compile with pdflatex on my not-so-old desktop. It's much faster to do this just once, and then include the PDF file with \includegraphics.)
    – user86418
    Oct 19, 2013 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .