3

I have the following triangle in TikZ MWE:

\documentclass[tikz]{standalone}
\usepackage{pgfplots,mathtools} 
\usetikzlibrary{hapes,decorations.pathreplacing}  
\usetikzlibrary{patterns}
\definecolor{RoyalAzure}{rgb}{0.0, 0.22, 0.66}  

\begin{document}

\begin{tikzpicture}
\draw[pattern color=black!50!white,pattern=dots, line width=0.6pt] (0,0) -- (2,3.4641) -- (4,0)--cycle;
\end{tikzpicture}

\end{document}

that generates:

Triangle

I would like to project this triangle to the surface of a sphere, much like this figure:

Bloch sphere

How can I do this?

5

The angles of the triangle on the sphere are 3 times 90 degrees whereas the angles of the triangle in the plane are 60 degrees each. Therefore I do not precisely understand what is meant by "project". If it is meant that the triangle on the sphere should also have three equal angles, you could do e.g.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{patterns,backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{30}
\begin{tikzpicture}[tdplot_main_coords,declare function={R=pi;}]
 \shade[tdplot_screen_coords,ball color=gray,opacity=0.5] (0,0) coordinate(O)
  circle[radius=R];
 \draw plot[variable=\x,domain=\tdplotmainphi-180:\tdplotmainphi,smooth]
 ({R*cos(\x)},{R*sin(\x)},0);
 \draw[blue,pattern=dots,pattern color=blue] 
   plot[variable=\x,domain=90:00,smooth] (0,{-R*sin(\x)},{R*cos(\x)})
    coordinate   (p1) 
 -- plot[variable=\x,domain=0:90,smooth] ({R*sin(\x)},0,{R*cos(\x)})
   coordinate   (p2) 
 -- plot[variable=\x,domain=0:90,smooth] ({R*cos(\x)},{-R*sin(\x)},0)
   coordinate   (p3);
   \begin{scope}[on background layer]
    \foreach \X in {1,2,3}
    { \draw[dashed] (O) -- (p\X); }
   \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

An alternative could be to use nonlinear transformations to project anything you want on a sphere. We have used this for the Christmas balls in this video (at a time in which the atmosphere were better...). However, when doing this, we run into the above-mentioned problem that the triangle has different angles on the sphere.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{patterns}
\usepgfmodule{nonlineartransformations}
\makeatletter
% from https://tex.stackexchange.com/a/434247/121799
\tikzdeclarecoordinatesystem{sphere}{
    \tikz@scan@one@point\relax(#1)
    \spheretransformation
}
% 
\def\spheretransformation{% similar to the pgfmanual section 103.4.2
\pgfmathsincos@{\pgf@sys@tonumber\pgf@x}%
\pgfmathsetmacro{\relX}{\the\pgf@x/28.3465}%
\pgfmathsetmacro{\relY}{\the\pgf@y/28.3465}%min(max(
\pgfmathsetmacro{\myx}{28.3465*\Radius*cos(min(max((\relY/\Radius)*(180/pi),-90),90))*sin(min(max((\relX/\Radius)*cos(min(max((\relY/\Radius)*(180/pi),-90),90))*(180/pi),-90),90))}
\pgfmathsetmacro{\myy}{28.3465*\Radius*sin(min(max((\relY/\Radius)*(180/pi),-90),90))}%\typeout{(\relX,\relY)->(\myx,\myy)}%
\pgf@x=\myx pt%
\pgf@y=\myy pt%
} 
\makeatother
\begin{document}
\begin{tikzpicture}[pics/trian/.style={code={
\draw[pattern color=black!50!white,pattern=dots, line width=0.6pt] (0,0) -- (2,3.4641) -- (4,0)--cycle;}}]
 \pgfmathsetmacro{\Radius}{4}
 \shade[ball color=red] (0,0) circle[radius=\Radius];
 \begin{scope}[xshift=-10cm]
  \path (0,0) pic{trian};
 \end{scope}
 \begin{scope}[transform shape nonlinear=true]
  \pgftransformnonlinear{\spheretransformation}
  \pic[local bounding box=box1] at (0,0) {trian};
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    In this case, I did only want a triangle with the same angles but on the surface of the sphere. I do have other examples where I want to perform a strict projection - but you have very helpfully included an example on how to do that too! Thank you. P.s. a lot of marmots in the video :D – Sid Apr 15 at 15:07
  • For the first method you have, is it possible you could add the axes as in the image in the question? – Sid Apr 15 at 16:31
  • @Sid Done....... – marmot Apr 15 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.