TikZ Saturn Rings – Creating Saturn Rings with TikZ

tikz-pgf

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}  

Best Answer

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