28

The planet and a ring are easily drawn. The challenge is to layer them in such a way that the far side of the ring is hidden from view behind the planet, and the near side of the ring eclipses the planet in the foreground. My instinct tells me that this can be done using clipping, scopes, or the backgrounds package, but I apparently lack the cleverness to turn the trick.

Here's the code for Saturn and one ring:

\documentclass{article}

\usepackage{tikz}

\begin{document}

%Saturn on top
\begin{tikzpicture}
\draw[fill=blue] (0,-.2) circle [x radius=4, y radius=1];
\draw[fill=white] (0,0) circle [x radius=3, y radius=.5];
\draw[fill=red] (0,0) circle [radius=2];
\end{tikzpicture}

\bigskip

%ring on top
\begin{tikzpicture}
\draw[fill=red] (0,0) circle [radius=2];    
\draw[fill=blue] (0,-.2) circle [x radius=4, y radius=1];
\draw[fill=white] (0,0) circle [x radius=3, y radius=.5];    
\end{tikzpicture}

\end{document}  

5 Answers 5

27

Example with some clipping:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  % red Saturn as background
  \draw[fill=red] (0,0) circle [radius=2];
  % blue ring with white in the middle
  \draw[fill=blue, even odd rule]
    (0,-.2) circle [x radius=4, y radius=1]
    (0,0) circle [x radius=3, y radius=.5];
  % redraw red Saturn in the foreground with clipping
  \begin{scope}
    \clip[overlay] (-2.1,0) rectangle (2.1,2.1);
    \draw[fill=red] (0,0) circle [radius=2];
  \end{scope}
\end{tikzpicture}

\end{document}

Remarks:

  • Instead of filling the interior of the ring with white, the code uses option even odd rule for filling. The "white" interior is specified twice for filling. According to that rule, it is not filled with the fill color.

Result

2
  • 2
    Bravo! That's exactly what I thought could be done, but couldn't do it. Thanks, Heiko. Jan 25, 2014 at 20:41
  • That looks strangely familiar.
    – E.P.
    Jan 26, 2014 at 2:45
18

Another example:

\documentclass[x11names]{beamer}
\usepackage{lmodern,tikz}
\usetikzlibrary{decorations.markings,overlay-beamer-styles}

\pgfdeclareverticalshading{Saturn}{2cm}{
color(0cm)=(AntiqueWhite4);
color(0.1cm)=(LightGoldenrod2);
color(0.15cm)=(Bisque1);
color(0.25cm)=(LemonChiffon3);
color(0.3cm)=(NavajoWhite3);
color(0.6cm)=(LemonChiffon3);
color(0.7cm)=(Wheat2);
color(0.85cm)=(Wheat1);
color(0.95cm)=(Bisque3);
color(1.25cm)=(Cornsilk2);
color(1.5cm)=(Bisque3);
color(1.7cm)=(AntiqueWhite3);
color(1.9cm)=(AntiqueWhite4)
}

\tikzset{satellite orbit/.style args={at pos #1 with #2}{
   postaction=decorate,
   decoration={
    markings,
    mark=
    at position #1
      with
      {
       #2
      }
    }
  },
}

\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}[rotate=21]

\path[shading=Saturn,shading angle=21] (0,0) circle [radius=2];

\path[inner color=LemonChiffon3,outer color=Bisque3,even odd rule]
    (0,-.2) circle [x radius=4, y radius=1.25]
    (0,-.15) circle [x radius=3.8, y radius=1.2]; 

\path[inner color=Bisque2,outer color=NavajoWhite3,even odd rule]
    (0,-.15) circle [x radius=3.8, y radius=1.2]
    (0,-.15) circle [x radius=3.6, y radius=1.1]
    ;  

\path[left color=AntiqueWhite3,right color=Wheat3!98!black,even odd rule,
shading angle=31]
    (0,0) circle [x radius=3, y radius=.75]
    (0,-.15) circle [x radius=3.6, y radius=1.1];

\path[inner color=NavajoWhite2,outer color=Bisque3,even odd rule]    
    (0,0) circle [x radius=3, y radius=.75]
    (0,0) circle [x radius=2.8, y radius=.725]; 

\foreach \x[count=\xi] in {0.35,0.4,...,1,0,0.05,...,0.25}{
\tikzset{visibility/.style={
    shading=Saturn,
    visible on=<\xi>,
  }
}
\ifnum\xi<3
\tikzset{visibility/.append style={
    background default shade={shading=Saturn},
    background shade={right color=gray,left color=gray!80},
    shade on=<\xi>,
  }
}
\fi
\ifnum\xi>16
\tikzset{visibility/.append style={
    background default shade={shading=Saturn},
    background shade={left color=gray,right color=gray!80},
    shade on=<\xi>,
  }
}
\fi
\path[satellite orbit=%
  at pos {\x} with {%
  \node[circle,visibility]{};%
  }](0,-.2) circle [x radius=5, y radius=1.45];
}

\begin{scope}
    \clip[overlay] (-2.1,0) rectangle (2.1,2.1);
    \path[shading=Saturn,shading angle=21] (0,0) circle [radius=2];
\end{scope} 

\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

The result:

enter image description here

10
  • Really cool drawing! Jan 29, 2014 at 16:17
  • Amazing code, Claudio! In other news, Houston, we have a problem... :) Jan 29, 2014 at 17:03
  • @PauloCereda: the birth of alien ducks :) What else will you invent? ;) Jan 29, 2014 at 17:50
  • @Claudio: my original plan was to replace the moon with the duck, but apparently I injected the duck code in the wrong place. :) Jan 29, 2014 at 18:06
  • @PauloCereda: oh, I may have some clues for that; let me have a look tomorrow. Jan 29, 2014 at 19:02
16

Not sure I like the colour scheme, so here's a more restrained Metapost version, featuring the useful buildcycle macro.

% prologues :=3; outputtemplate := saturn.eps; % uncomment if you want these
beginfig(1);
path globe, gap, ring[], limb[];
globe = fullcircle scaled 2cm;
gap   = fullcircle xscaled 3cm yscaled .8cm;
ring1  = fullcircle xscaled 4cm yscaled 1.2cm;
ring2  = ring1 scaled 0.93;
ring3  = ring1 scaled 0.89;
limb1 = buildcycle(subpath (5,7) of ring1, subpath (8,4) of globe);
limb2 = buildcycle(subpath (5,7) of gap, subpath (-2,6) of globe);
picture saturn; saturn = image(
fill ring1 withcolor .1red+.1green+.4white;
fill ring2 withcolor .2white;
fill ring3 withcolor .1red+.1green+.6white;
unfill gap; 
fill limb1 withcolor .2red+.1green+.7white;
fill limb2 withcolor .2red+.1green+.7white;
);
draw saturn rotated 30;
endfig;
end.  % don't include this if you are making this part of another file

enter image description here

3
  • Really cool drawing! Jan 29, 2014 at 16:42
  • Impressively economical code. Jan 29, 2014 at 22:58
  • I tried to learn MetaPost a bit, did not see buildcycle yet. You made a lot of impressive examples here. Would you like to write a MetaPost article on LaTeX-Community.org on MetaPost which explains some clever features, motivating potential learners with such nice images? I gladly return the favor with a 500 bounty, but more important is that readers there will like it for sure and we will bring MetaPost again in a focus. You could contact me via [email protected] if you like.
    – Stefan Kottwitz
    Jan 28, 2015 at 15:37
15

With PSTricks just for fun as usual. No clipping used here.

\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}[linecolor=blue](-4,-2)(4,2)
    \pscustom*{\psellipticarcn(4,1){180}{0}\psellipticarc(0,.2)(3,.5){0}{180}}
    \pscircle*[linecolor=red]{2}
    \pscustom*{\psellipticarc(4,1){180}{0}\psellipticarcn(0,.2)(3,.5){0}{180}}
\end{pspicture}
\end{document}

enter image description here

2
  • 3
    Can you make it animated with an actual asteroid belt rotating :-) just saying....
    – azetina
    Jan 25, 2014 at 23:24
  • 1
    @azetina: I am thinking of it. Jan 25, 2014 at 23:40
2

Rather than use clipping, you can also draw semi-circles

\documentclass{article}

\usepackage{tikz}
\usepackage[x11names]{xcolor}

\begin{document}

\begin{tikzpicture}
% Top half
\fill [Wheat1] (0:1) arc (0:180:1) -- cycle;

% Ring
\path[inner color=black,outer color=Cornsilk1,even odd rule]    
    (0, 0) circle [x radius = 1.5, y radius = .25]
    (0, 0) circle [x radius = 1.7, y radius = .3]
    (0, 0) circle [x radius = 1.75, y radius = .33]
    (0, 0) circle [x radius = 1.95, y radius = .38]; 

% Bottom half
\fill [Wheat1] (180:1) arc (180:360:1) -- cycle;

\end{tikzpicture}
\end{document}

enter image description here

1
  • Maybe with some 3D effects you could make it look like a sphere. +1
    – Sebastiano
    Mar 28, 2020 at 20:30

You must log in to answer this question.

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