Skip to content

Instantly share code, notes, and snippets.

@mcnees
Created September 3, 2017 01:17
Show Gist options
  • Save mcnees/044cd4ab4e4c62dbbe997a8dbf701fab to your computer and use it in GitHub Desktop.
Save mcnees/044cd4ab4e4c62dbbe997a8dbf701fab to your computer and use it in GitHub Desktop.
Shrinking sphere in LaTeX with PGF/TikZ
\documentclass[crop=true, border=10pt]{standalone}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\definecolor{plum}{rgb}{0.36078, 0.20784, 0.4}
\definecolor{chameleon}{rgb}{0.30588, 0.60392, 0.023529}
\definecolor{cornflower}{rgb}{0.12549, 0.29020, 0.52941}
\definecolor{scarlet}{rgb}{0.8, 0, 0}
\definecolor{brick}{rgb}{0.64314, 0, 0}
\definecolor{sunrise}{rgb}{0.80784, 0.36078, 0}
\definecolor{lightblue}{rgb}{0.15,0.35,0.75}
\begin{document}
\begin{tikzpicture}[scale=.6]
% Draw the grid.
\draw [cornflower!20,step=0.25,thin] (-3,-3) grid (3,3);
\draw [cornflower!40,step=1.0,thin] (-3,-3) grid (3,3);
\node at (0,-3.6) [xshift=0em, yshift=0em] {$R_1$};
\draw (-2,0) arc (180:360:2cm and 0.6cm);
\draw[dashed] (-2,0) arc (180:0:2cm and 0.6cm);
\draw (0,0) circle (2cm);
\shade[ball color=lightblue!40!white,opacity=0.40] (0,0) circle (2cm);
\end{tikzpicture}
%
\hskip.5em
%
\begin{tikzpicture}[scale=.6]
\draw [cornflower!20,step=0.25,thin] (-3,-3) grid (3,3);
\draw [cornflower!40,step=1.0,thin] (-3,-3) grid (3,3);
\node at (0,-3.6) [xshift=0em, yshift=0em] {$R_2 = 0.6 \times R_1$};
\draw (-.6*2,0) arc (180:360:.6*2cm and .6*0.6cm);
\draw[dashed] (-.6*2,0) arc (180:0:.6*2cm and .6*0.6cm);
\draw (0,0) circle (.6*2cm);
\shade[ball color=lightblue!50!white,opacity=0.50] (0,0) circle (.6*2cm);
\end{tikzpicture}
%
\hskip.5em
%
\begin{tikzpicture}[scale=.6]
\draw [cornflower!20,step=0.25,thin] (-3,-3) grid (3,3);
\draw [cornflower!40,step=1.0,thin] (-3,-3) grid (3,3);
\node at (0,-3.6) [xshift=0em, yshift=0em] {$R_3 = 0.3 \times R_1$};
\draw (-.3*2,0) arc (180:360:.3*2cm and .3*0.6cm);
\draw[dashed] (-.3*2,0) arc (180:0:.3*2cm and .3*0.6cm);
\draw (0,0) circle (.3*2cm);
\shade[ball color=lightblue!60!white,opacity=0.60] (0,0) circle (.3*2cm);
\end{tikzpicture}
%
\hskip.5em
%
\begin{tikzpicture}[scale=.6]
\draw [cornflower!20,step=0.25,thin] (-3,-3) grid (3,3);
\draw [cornflower!40,step=1.0,thin] (-3,-3) grid (3,3);
\node at (0,-3.6) [xshift=0em, yshift=0em] {$R_4 = 0.1 \times R_1$};
\draw (-.1*2,0) arc (180:360:.1*2cm and .1*0.6cm);
\draw[dashed] (-.1*2,0) arc (180:0:.1*2cm and .1*0.6cm);
\draw (0,0) circle (.1*2cm);
\shade[ball color=lightblue!80!white,opacity=0.80] (0,0) circle (.1*2cm);
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment