Projection of circles onto a spherical surface

Here we got a semi sphere. On the base area we place circles, which are then projected onto the surface of sphere.

Using polar coordinates for the circles seems to be a good choice, but for now we take cartesian coordinates. We draw using layers.

This example was written by Mark Wibrow answering a question on TeX.SE.


dome

Edit and compile if you like:

% Projection of circles onto a spherical surface
% Author: Mark Wibrow
\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\pgfdeclarelayer{dome floor}
\pgfdeclarelayer{dome}
\pgfdeclarelayer{dome surface}
\pgfsetlayers{dome floor,main,dome,dome surface}
\def\addcircle#1#2#3#4{%
\begingroup%
\pgfmathparse{#1}\let\R=\pgfmathresult
\pgfmathparse{#2}\let\cx=\pgfmathresult
\pgfmathparse{#3}\let\cy=\pgfmathresult
\pgfmathparse{#4}\let\r=\pgfmathresult
\begin{pgfonlayer}{dome floor}
\draw [blue!45!black, fill = blue!45, fill opacity = 0.25]
plot [domain = 0:360, samples = 40, variable = \i]
(\cx+\r*cos \i, \cy+\r*sin \i, 0) -- cycle;
\end{pgfonlayer}
\begin{pgfonlayer}{dome surface}
\draw [red!75!black, fill = red!75, fill opacity = 0.25]
plot [domain = 0:360, samples = 60, variable = \t]
(\cx+\r*cos \t,\cy+\r*sin \t,
{sqrt(max(\R^2-(\cx+\r*cos(\t))^2-(\cy+\r*sin(\t))^2, 0))})
-- cycle;
\end{pgfonlayer}
\endgroup%
}
\begin{tikzpicture}[x = (-30:1cm), y = (30:1cm), z = (90:1cm)]
\def\R{6}
\begin{pgfonlayer}{dome floor}
\draw (-\R,0,0) -- (\R,0,0);
\draw (0,-\R,0) -- (0,\R,0);
\draw plot [domain = 0:360, samples = 90, variable = \i]
(\R*cos \i, \R*sin \i, 0) -- cycle;
\end{pgfonlayer}
\draw (0,0,0) -- (0,0,\R);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Click to download: dome.texdome.pdf
Open in Overleaf: dome.tex