8

I try to draw this image. enter image description here where $\alpha_1$ and $\alpha_2$ are circumferences in the unit sphere, passing through C=(1/sqrt(3),1/sqrt(3),1/sqrt(3)) with center at the origin of coordinates, that is, they are geodesic. It is not necessary to graph $\alpha_1$ or $\alpha_2$, but it would look nice if it were done.. I have some complications like for example the label comes out too big. I don't know how to rotate the graphic to make it look like my image. I don't know how to paint that little rectangle, either with lines or a whole color. Any suggestion? On the other hand, I would also like the contour of the sphere to appear with a not so thick line, I tried to do it by plotting the largest circumference but if I plan to rotate it it does not work for me that is why I did not put it in the code.

enter image description here This is my code,

\documentclass[border={10pt}]{standalone}
\usepackage{tikz}  
\usepackage{pstricks-add}
\newrgbcolor{mycolor}{0 153 216}

\begin{document}

\begin{tikzpicture}

\shade[ball color=mycolor] (0,0) circle (1cm); \pgfmathsetmacro{\a}{25/16}; \pgfmathsetmacro{\d}{\a/(sqrt(3))}; \pgfmathsetmacro{\r}{sqrt(1-\d*\d)}; \pgfmathsetmacro{\e}{1/sqrt(2)}; \pgfmathsetmacro{\f}{1/sqrt(6)};

\pgfmathsetmacro{\aa}{53/32}; \pgfmathsetmacro{\dd}{\aa/(sqrt(3))}; \pgfmathsetmacro{\rr}{sqrt(1-\dd*\dd)};

\draw plot[variable=\x,domain=360:0,samples=181] ({\a/3+\e\rcos(\x)-\f\rsin(\x)},{\a/3-\e\rcos(\x)-\f\rsin(\x)},{\a/3+2\f\r*sin(\x)});

\draw plot[variable=\x,domain=360:0,samples=181] ({\aa/3+\e\rrcos(\x)-\f\rrsin(\x)},{\aa/3-\e\rrcos(\x)-\f\rrsin(\x)},{\aa/3+2\f\rr*sin(\x)});

\draw[fill] ({1/sqrt(3)},{1/sqrt(3)},{1/sqrt(3)}) circle (0.02) node[below left] {$C$};

\end{tikzpicture} \end{document}

Zaragosa
  • 599
  • You don't need to load pstricks-add just to define a new color. You can do this just with \definecolor{mycolor}{rgb}{0, 153, 216}. – Jasper Habicht Nov 21 '21 at 13:21

2 Answers2

11

There has already been made some effort to simplify drawing on spheres in this amazing answer (therefore, credit should go to the author of the linked answer, too). I took over the idea and two of the basic code components from there and created something that you might be able to use:

\documentclass[tikz,margin=5pt]{standalone}
\usepackage{tikz}

% Style to set camera angle, like PGFPlots view style \tikzset{viewport/.style 2 args={ x={({cos(-#1)1cm},{sin(-#1)sin(#2)1cm})}, y={({-sin(-#1)1cm},{cos(-#1)sin(#2)1cm})}, z={(0,{cos(#2)*1cm})} }}

% Convert from spherical to cartesian coordinates \newcommand{\ToXYZ}[2]{ {sin(#1)cos(#2)}, % X coordinate {cos(#1)cos(#2)}, % Y coordinate {sin(#2)} % Z (vertical) coordinate }

\begin{document} \def\RotationX{-10} \def\RotationY{30} \begin{tikzpicture}[scale=4]

\path[draw] (0,0) circle (1);

\begin{scope}[viewport={\RotationX}{\RotationY}]

    \draw[variable=\t, smooth] 
        plot[domain=90-\RotationY:-90-\RotationY] (\ToXYZ{0}{\t})
        plot[domain=90-\RotationX:-90-\RotationX] (\ToXYZ{\t}{0});
    \draw[densely dashed, variable=\t, smooth]
        plot[domain=90-\RotationY:270-\RotationY] (\ToXYZ{0}{\t})
        plot[domain=90-\RotationX:270-\RotationX] (\ToXYZ{\t}{0});

    \draw[red, variable=\t, smooth, domain=0:360] 
        plot (\ToXYZ{20*sin(\t)}{20*cos(\t)}) 
        plot (\ToXYZ{10*sin(\t)}{10*cos(\t)});

    \fill[blue, opacity=.25, variable=\t, smooth] 
        plot[domain=0:90] (\ToXYZ{20*sin(\t)}{20*cos(\t)}) -- 
        plot[domain=10:20] (\ToXYZ{\t}{0}) --
        plot[domain=90:0] (\ToXYZ{10*sin(\t)}{10*cos(\t)}) -- 
        plot[domain=10:20] (\ToXYZ{0}{\t}) --
        cycle;

    \node[circle, fill, inner sep=1pt, label={240:$C$}] at (\ToXYZ{0}{0}) {};

    \node[circle, fill, inner sep=1pt, label={90:$P$}] at (\ToXYZ{10*sin(30)}{10*cos(30)}) {};

\end{scope}

\end{tikzpicture} \end{document}

enter image description here


If you want to draw great circles other than these two regular ones, the easiest way would probably be to rotate them using the option rotate around y. Then you don't need to do the math.

For the marked area, you can simply adjust the domain option and specify other angles.

One example with one of the great circles turned by −20° and the marked area adjusted respectively (covering now 110° of the part between the two red circles):

\documentclass[tikz,margin=5pt]{standalone}
\usepackage{tikz}

% Style to set camera angle, like PGFPlots view style \tikzset{viewport/.style 2 args={ x={({cos(-#1)1cm},{sin(-#1)sin(#2)1cm})}, y={({-sin(-#1)1cm},{cos(-#1)sin(#2)1cm})}, z={(0,{cos(#2)*1cm})} }}

% Convert from spherical to cartesian coordinates \newcommand{\ToXYZ}[2]{ {sin(#1)cos(#2)}, % X coordinate {cos(#1)cos(#2)}, % Y coordinate {sin(#2)} % Z (vertical) coordinate }

\begin{document} \def\RotationX{-10} \def\RotationY{30} \begin{tikzpicture}[scale=4]

\path[draw] (0,0) circle (1);

\begin{scope}[viewport={\RotationX}{\RotationY}]

    \draw[variable=\t, smooth] 
        plot[domain=90-\RotationY:-90-\RotationY, rotate around y=-20] (\ToXYZ{0}{\t})
        plot[domain=90-\RotationX:-90-\RotationX] (\ToXYZ{\t}{0});
    \draw[densely dashed, variable=\t, smooth]
        plot[domain=90-\RotationY:270-\RotationY, rotate around y=-20] (\ToXYZ{0}{\t})
        plot[domain=90-\RotationX:270-\RotationX] (\ToXYZ{\t}{0});

    \draw[red, variable=\t, smooth, domain=0:360] 
        plot (\ToXYZ{20*sin(\t)}{20*cos(\t)}) 
        plot (\ToXYZ{10*sin(\t)}{10*cos(\t)});

    \fill[blue, opacity=.25, variable=\t, smooth] 
        plot[domain=-20:90] (\ToXYZ{20*sin(\t)}{20*cos(\t)}) -- 
        plot[domain=10:20] (\ToXYZ{\t}{0}) --
        plot[domain=90:-20] (\ToXYZ{10*sin(\t)}{10*cos(\t)}) -- 
        plot[domain=10:20, rotate around y=-20] (\ToXYZ{0}{\t}) --
        cycle;

    \node[circle, fill, inner sep=1pt, label={240:$C$}] at (\ToXYZ{0}{0}) {};

    \node[circle, fill, inner sep=1pt, label={90:$P$}] at (\ToXYZ{10*sin(30)}{10*cos(30)}) {};

\end{scope}

\end{tikzpicture} \end{document}

enter image description here

PS: In case you find that the paths are not plotted smoothly enough, you can add the option samples= (like in your example) and state a number that is high enough to satisfy your needs.

  • Thank you very much the graph is great, a question if I want the separation of the curves that pass through C to have a particular angle for example 120 or 150?. – Zaragosa Nov 21 '21 at 16:10
  • 1
    @Zaragosa I added a simple way to adjust the angle of the great circles and of the marked area. – Jasper Habicht Nov 21 '21 at 17:51
  • 1
    Thank you so much!!! It's fantastic! – Zaragosa Nov 21 '21 at 17:57
  • 1
    I corrected the path for the marked areas. I had cheated a bit and had just drawn sraight lines where the path that demarcates the area runs along the great circles. Now, it is precise. The correction is hardly visible anyways. – Jasper Habicht Nov 21 '21 at 23:31
  • 1
    Thank you, I left my final product as an answer, with the sole purpose that people can see what my initial idea was like, and thanks to your help I was able to do it. – Zaragosa Nov 22 '21 at 02:01
4

Thank you very much for Jasper Habicht's answer, here I will leave the modifications that I made (just so that future people can see how everything turned out): enter image description here

I made the code before your last modification:

\documentclass[tikz,margin=5pt]{standalone}
\usepackage{tikz}
\usepackage{amsfonts}

\definecolor{mycolor}{rgb}{0, 153, 216}

% Style to set camera angle, like PGFPlots view style \tikzset{viewport/.style 2 args={ x={({cos(-#1)1cm},{sin(-#1)sin(#2)1cm})}, y={({-sin(-#1)1cm},{cos(-#1)sin(#2)1cm})}, z={(0,{cos(#2)*1cm})} }}

% Convert from spherical to cartesian coordinates \newcommand{\ToXYZ}[2]{ {sin(#1)cos(#2)}, % X coordinate {cos(#1)cos(#2)}, % Y coordinate {sin(#2)} % Z (vertical) coordinate }

\begin{document} \def\RotationX{-20} \def\RotationY{30} \begin{tikzpicture}[scale=4]

\path[ball color= mycolor, draw] (0,0) circle (1);

\begin{scope}[viewport={\RotationX}{\RotationY}]

    \draw[variable=\t, smooth, line width=0.2pt] 
        plot[domain=90-\RotationY:-90-\RotationY, rotate around y=-20] (\ToXYZ{0}{\t})
        plot[domain=90-\RotationX:-90-\RotationX, rotate around y=110] (\ToXYZ{\t}{0});

    \draw[densely dashed, variable=\t, smooth, line width=0.5pt, opacity=0.3]
        plot[domain=90-\RotationY:270-\RotationY, rotate around y=-20] (\ToXYZ{0}{\t})
        plot[domain=90-\RotationX:270-\RotationX, rotate around y=110] (\ToXYZ{\t}{0});

    \draw[densely dashed, variable=\t, smooth]
        plot[domain=-160:-20] (\ToXYZ{15*sin(\t)}{15*cos(\t)});

    \fill[color=blue!80!white, opacity=1, variable=\t, smooth] 
        plot[domain=-21:201] (\ToXYZ{25*sin(\t)}{25*cos(\t)}) --
        plot[domain=201:-20] (\ToXYZ{15*sin(\t)}{15*cos(\t)}) -- cycle;

    \draw[black, variable=\t, smooth, domain=0:360, line width=0.4pt] 
        plot[domain=-21:201] (\ToXYZ{25*sin(\t)}{25*cos(\t)})
        plot[domain=-21:201] (\ToXYZ{15*sin(\t)}{15*cos(\t)});

    \draw[black, variable=\t, smooth, domain=0:360, line width=0.4pt] 
        plot[domain=55-\RotationY:45-\RotationY, rotate around y=-20] (\ToXYZ{0}{\t})
        plot[domain=5-\RotationX:-5-\RotationX, rotate around y=110] (\ToXYZ{\t}{0});

    \node[circle, fill, inner sep=1pt] at (\ToXYZ{0}{0}) {};

    \node[circle, fill, inner sep=1pt] at (\ToXYZ{15*sin(140)}{15*cos(140)}) {};

    \node[] at (1,0.5,0.5) {\Large{$\mathbb S^2$}};
    \node[] at (-0.14,0.1,0.6) {\Large{$\gamma$}};
    \node[] at (-0.2,0.1,0.4) {\Large{$p$}};
\end{scope}

\end{tikzpicture} \end{document}

Zaragosa
  • 599