# How to improve this stereographic projection

I am trying to draw the stereographic projection in the following way:

\documentclass{article}
\usepackage{mathtools}
\usepackage{wrapfig}
\usepackage{pgf,tikz,pgfplots}
\usetikzlibrary{decorations.pathreplacing, calligraphy}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{patterns}
\usetikzlibrary{calc}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\coordinate (A) at (3,-0.25);
\coordinate (P) at (0,2);
\draw (0,0) circle (2);
\draw (0,0) ellipse (2 and 0.5);
\draw (-4.5,-1) -- (3.5,-1) -- (4.5,1) node[anchor=south east] {\scriptsize$z=0$} -- (-3.5,1) -- cycle;
\draw (A) -- (P) coordinate[pos=0.47](B);
\path (A) node[circle, fill, inner sep=1pt, label=below:{\scriptsize$P(x,y,0)$}]{};
\path (B) node[circle, fill, inner sep=1pt, label=left:{\scriptsize$(\xi,\eta,\zeta)$}]{};
\path (P) node[circle, fill, inner sep=1pt, label=above:{\scriptsize$(0,0,1)$}]{};
\draw [dashed] (-2,0) -- (2,0);
\end{tikzpicture}
\end{figure}
\end{document}


What I want to acheive are dotted lines along the red lines in the following picture thus generated:

Also, I want to add another dotted line along the blue line which not there in the MWE.

You just need to draw the dashed and solid parts in separate paths, so using arcs instead of circles for the arced paths.

The 30 degree angle was found by trial and error, but it could be calculated if needed.

\documentclass[border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (3,-0.25);
\coordinate (P) at (0,2);

\draw [dashed] (210:2cm)

\draw [dashed] (80:2cm and 0.5cm) -- (260:2cm and 0.5cm);
\draw [dashed] (150:2cm) coordinate(ul) -- (30:2cm) coordinate(ur);

\draw (-4.5,-1) -- (3.5,-1) -- (4.5,1) node[anchor=south east] {\scriptsize$z=0$} -- (ur) (ul) -- (-3.5,1) -- (-4.5,-1);

\draw (A) -- (P) coordinate[pos=0.47](B);
\path (A) node[circle, fill, inner sep=1pt, label=below:{\scriptsize$P(x,y,0)$}]{};
\path (B) node[circle, fill, inner sep=1pt, label=left:{\scriptsize$(\xi,\eta,\zeta)$}]{};
\path (P) node[circle, fill, inner sep=1pt, label=above:{\scriptsize$(0,0,1)$}]{};
\draw [dashed] (-2,0) -- (2,0);

\end{tikzpicture}
\end{document}

• I am sorry if my question is misunderstood. I need to have dotted lines replacing the lines generated by the codes in the MWE. The places where I need the dotted lines are mentioned by the red dashes in the attached picture. And the blue line is absent in the MWE. Apr 16, 2020 at 19:52
• @SubhajitPaul Sorry, I misunderstood. Anyways, the same principle can be used, in principle just do the same thing to draw the segments which should be black. Will update in a bit. I don't understand what you mean about the blue line. It's drawn in my code. If you don't want it to be blue, just remove the colour specification. Apr 16, 2020 at 20:01
• The blue line is not there in the code, so that is why I have marked it with another colour. The entire diagram will not have any coloured lines. Apr 16, 2020 at 20:12
• @SubhajitPaul Well as I said, then you just needed to remove blue. Anyways, I updated the code. Apr 16, 2020 at 20:18
• @SubhajitPaul Use \path (A) -- (P) coordinate[pos=0.47](B); and then \draw (A) -- (B); \draw [dashed] (B) -- (P); Apr 16, 2020 at 20:54

This is an orthographic projection of a stereographic projection. That is, 3d coordinate with an actual stereographic projection are used and projected on the screen via an orthographic projection. The dashed lines are achieved with an orgy of clips and reverse clips.

\documentclass{article}
\usepackage{tikz}
% based on
% https://tex.stackexchange.com/a/38995/121799
% https://tex.stackexchange.com/a/76216
% https://tex.stackexchange.com/a/59168/194703
% https://tex.stackexchange.com/q/448920/194703
\makeatletter
\tikzset{
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\tikzset{even odd clip/.code={\pgfseteorule},
protect/.code={
\clip[overlay,even odd clip,reuse path=#1]
(current bounding box.south west) rectangle (current bounding box.north east)
%(-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)
;
}}
\makeatother
\usetikzlibrary{3d,perspective}
\begin{document}
\pgfmathsetmacro{\myaz}{10}
\begin{tikzpicture}[declare function={%
stereox(\x,\y)=2*\x/(1+\x*\x+\y*\y);%
stereoy(\x,\y)=2*\y/(1+\x*\x+\y*\y);%
stereoz(\x,\y)=(-1+\x*\x+\y*\y)/(1+\x*\x+\y*\y);},scale=2.5,
line join=round,line cap=round,
dot/.style={circle,fill,inner sep=1pt}]
\begin{scope}[3d view={\myaz}{15}]
\draw (-2,2) -- (-2,-2) coordinate (bl) -- (2,-2) coordinate (br)-- (2,2)
node[above left]{$z=0$};
\begin{scope}
\tikzset{protect=\pathSphere}
\draw (-2,2) -- (2,2);
\end{scope}
\begin{scope}
\clip[reuse path=\pathSphere];
\draw[dashed] (-2,2) -- (2,2);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\path[save path=\pathPlane] (\myaz:2) -- (\myaz+180:2) --(bl) -- (br) -- cycle;
\begin{scope}
\clip[use path=\pathPlane];
\draw[dashed,use path=\pathSphere];
\end{scope}
\begin{scope}
\tikzset{protect=\pathPlane}
\draw[use path=\pathSphere];
\end{scope}
\end{scope}
\draw (1.5,-1,0) node[dot,label=below:{$P(x,y,0)$}]{}
-- ({stereox(1.5,-1)},{stereoy(1.5,-1)},{stereoz(1.5,-1)})
node[dot,label=below left:{$(\xi,\eta,\zeta)$}](I){};
\draw[dashed] (I) -- (0,0,1) node[dot,label=above:{$(0,0,1)$}]{};
\end{scope}
\end{tikzpicture}
\end{document}


One can vary the view parameters and coordinates of the point on the plane. (This is all packed in one animation but the parameters can be varied separately.)

\documentclass[tikz,border=3mm]{standalone}
% based on
% https://tex.stackexchange.com/a/38995/121799
% https://tex.stackexchange.com/a/76216
% https://tex.stackexchange.com/a/59168/194703
% https://tex.stackexchange.com/q/448920/194703
\makeatletter
\tikzset{
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\tikzset{even odd clip/.code={\pgfseteorule},
protect/.code={
\clip[overlay,even odd clip,reuse path=#1]
(current bounding box.south west) rectangle (current bounding box.north east)
;
}}
\makeatother
\usetikzlibrary{3d,perspective}
\begin{document}
\foreach \X in {5,15,...,355}
{\pgfmathsetmacro{\myaz}{10+10*sin(\X)}
\begin{tikzpicture}[declare function={%
stereox(\x,\y)=2*\x/(1+\x*\x+\y*\y);%
stereoy(\x,\y)=2*\y/(1+\x*\x+\y*\y);%
stereoz(\x,\y)=(-1+\x*\x+\y*\y)/(1+\x*\x+\y*\y);
Px=1.75+0.5*sin(2*\X);Py=-1.5+0.5*cos(2*\X);amax=2.5;},scale=2.5,
line join=round,line cap=round,
dot/.style={circle,fill,inner sep=1pt}]
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\path[use as bounding box] (-3.5,-2) rectangle (3.5,2);
\path[save path=\pathSphere,ball color=gray,fill opacity=0.6]
\begin{scope}[3d view={\myaz}{15}]
\draw (-amax,amax) -- (-amax,-amax) coordinate (bl) -- (amax,-amax)
coordinate (br)-- (amax,amax)
node[above left]{$z=0$};
\begin{scope}
\tikzset{protect=\pathSphere}
\draw (-amax,amax) -- (amax,amax);
\end{scope}
\begin{scope}
\clip[reuse path=\pathSphere];
\draw[dashed] (-amax,amax) -- (amax,amax);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\path[save path=\pathPlane] (\myaz:amax) -- (\myaz+180:amax) --(bl) -- (br) -- cycle;
\begin{scope}
%\begin{pgfonlayer}{background}
\clip[use path=\pathPlane];
\draw[dashed,use path=\pathSphere];
%\end{pgfonlayer}
\end{scope}
\begin{scope}
\tikzset{protect=\pathPlane}
\draw[use path=\pathSphere];
\end{scope}
\begin{pgfonlayer}{background}
\fill[blue!30,fill opacity=0.6]
-- (-amax,0) -- (-amax,amax) -- (amax,amax) -- (amax,0) -- cycle;
\end{pgfonlayer}
\fill[blue!30,fill opacity=0.6]
-- (-amax,0) -- (-amax,-amax) -- (amax,-amax) -- (amax,0) -- cycle;
\end{scope}
\draw (Px,Py,0) node[dot,label=below:{$P(x,y,0)$}]{}
-- ({stereox(Px,Py)},{stereoy(Px,-1)},{stereoz(Px,Py)})
node[dot,label=below left:{$(\xi,\eta,\zeta)$}](I){};
\begin{pgfonlayer}{background}
\draw[dashed] (I) -- (0,0,1) node[dot,label=above:{$(0,0,1)$}]{};
\end{pgfonlayer}
\end{scope}
\end{tikzpicture}}
\end{document}


• Well, your answer looks even more charming but the code is not compiling! Should I update the question with the error messages? Apr 16, 2020 at 20:38
• @SubhajitPaul You can. (If I had to bet I'd say you have an older TeX installation and perspective is not available there.)
– user194703
Apr 16, 2020 at 20:41
• That is true. I figured it out. Let me update it and will refer back to you tomorrow. Thanks for your effort. Apr 16, 2020 at 21:06
• How was the animation produced from the LaTeX/TikZ output, which is just a series of static frames? Sep 3, 2022 at 17:43