0

I am trying to draw a spherical triangle $ABC$ and its polar counterpart $A'B'C'$ like in the picture

enter image description here

Is this possible using TiKz. There was a similar question in TikZ - Spherical triangles but without answer.

Averroes2
  • 177
  • I already saw that one, but I have problems to make it look like above. – Averroes2 Apr 01 '21 at 09:32
  • See https://github.com/matthias-wolff/tikz-3dplot-circleofsphere. BTW, the answer you accepted in the other question is wrong. I am not suggesting you should accept mine, which is also wrong, but this is just to inform you that it is incorrect. With the tikz-3dplot-circleofsphere you can answer both questions. –  Apr 01 '21 at 14:18
  • One solution would be the circles $90^\circ$ from A B and C, but I don't believe it is the only solution. Every line of latitude is perpendicular to every line of longitude. – John Kormylo Apr 01 '21 at 21:42
  • I created the objects you need to draw the triangles in the answer to the question https://tex.stackexchange.com/questions/551460/format-line-properties-when-it-appears-behind-another-object-in-tikz/558422#558422 Maybe it is not the simplest way to do it, but it might work. – Daniel N Apr 08 '21 at 15:23

1 Answers1

2

Here is a possible way to do it. It has lot of calculations, but they are simple (I hope) and quite repetitive.

\documentclass {standalone}
\usepackage    {tikz}
\usetikzlibrary{3d}
\usetikzlibrary{calc}
\usetikzlibrary{math}

% isometric axes \pgfmathsetmacro\xx{1/sqrt(2)} \pgfmathsetmacro\xy{1/sqrt(6)} \pgfmathsetmacro\zy{sqrt(2/3)}

% some functions (cross products) \tikzmath% {% function crossx(\mx,\my,\mz,\nx,\ny,\nz) {% cross product, x coordinate, normailized \pxx = \my\nz-\mz\ny; \pyy = \mz\nx-\mx\nz; \pzz = \mx\ny-\my\nx; return {\pxx/sqrt(\pxx\pxx+\pyy\pyy+\pzz\pzz)}; }; function crossy(\mx,\my,\mz,\nx,\ny,\nz) {% cross product, y coordinate, normailized \pxx = \my\nz-\mz\ny; \pyy = \mz\nx-\mx\nz; \pzz = \mx\ny-\my\nx; return {\pyy/sqrt(\pxx\pxx+\pyy\pyy+\pzz\pzz)}; }; function crossz(\mx,\my,\mz,\nx,\ny,\nz) {% cross product, z coordinate, normailized \pxx = \my\nz-\mz\ny; \pyy = \mz\nx-\mx\nz; \pzz = \mx\ny-\my\nx; return {\pzz/sqrt(\pxx\pxx+\pyy\pyy+\pzz*\pzz)}; }; }

\newcommand{\greatcircle}[6] % pole x, y, z, color, two orientation factors (+1/-1) {% \coordinate (P) at (#1,#2,#3); % pole \coordinate (N) at ($(0,0,0)!#61.25cm!(P)$); % these points are \coordinate (S) at ($-1(N)$); % used to clip the \coordinate (E) at ($(0,0,0)!-1.25cm!270:(P)$); % ellipses \coordinate (W) at ($-1(E)$); % ... \coordinate (NW) at ($(N)+(W)$); \coordinate (NE) at ($(N)+(E)$); \coordinate (SW) at ($(S)+(W)$); \coordinate (SE) at ($(S)+(E)$); \pgfmathsetmacro\ptheta{atan(#2/#1)} % pole, spherical coordinate theta \pgfmathsetmacro\pphi {#5acos(#3)} % pole, spherical coordinate phi \begin{scope} \clip (W) -- (SW) -- (SE) -- (E) -- cycle; \draw[rotate around z=\ptheta,rotate around y=\pphi,% canvas is xy plane at z=0,#4] (0,0) circle (1); \end{scope} \begin{scope} \clip (W) -- (NW) -- (NE) -- (E) -- cycle; \draw[rotate around z=\ptheta,rotate around y=\pphi,% canvas is xy plane at z=0,#4,densely dotted] (0,0) circle (1); \end{scope} }

\begin{document} \begin{tikzpicture}[line cap=round,line join=round,scale=2,% x={({-\xx cm,-\xy cm})},y={(\xx cm,-\xy cm)},z={(0 cm,\zy cm)}] % points A, B, C in spherical coordinates \def\atheta{55} \def\aphi {30} \def\btheta{10} \def\bphi {85} \def\ctheta{70} \def\cphi {80} % points A, B, C in cartesian coordinates \pgfmathsetmacro\ax{cos(\atheta)sin(\aphi)} \pgfmathsetmacro\ay{sin(\atheta)sin(\aphi)} \pgfmathsetmacro\az{cos(\aphi)}); \pgfmathsetmacro\bx{cos(\btheta)sin(\bphi)} \pgfmathsetmacro\by{sin(\btheta)sin(\bphi)} \pgfmathsetmacro\bz{cos(\bphi)}); \pgfmathsetmacro\cx{cos(\ctheta)sin(\cphi)} \pgfmathsetmacro\cy{sin(\ctheta)sin(\cphi)} \pgfmathsetmacro\cz{cos(\cphi)}); % polar points P, Q, R in cartesian coordinates \pgfmathsetmacro\px{crossx(\ax,\ay,\az,\bx,\by,\bz)} \pgfmathsetmacro\py{crossy(\ax,\ay,\az,\bx,\by,\bz)} \pgfmathsetmacro\pz{crossz(\ax,\ay,\az,\bx,\by,\bz)} \pgfmathsetmacro\qx{crossx(\cx,\cy,\cz,\ax,\ay,\az)} \pgfmathsetmacro\qy{crossy(\cx,\cy,\cz,\ax,\ay,\az)} \pgfmathsetmacro\qz{crossz(\cx,\cy,\cz,\ax,\ay,\az)} \pgfmathsetmacro\rx{crossx(\bx,\by,\bz,\cx,\cy,\cz)} \pgfmathsetmacro\ry{crossy(\bx,\by,\bz,\cx,\cy,\cz)} \pgfmathsetmacro\rz{crossz(\bx,\by,\bz,\cx,\cy,\cz)} % triangles \greatcircle{\ax}{\ay}{\az}{red} { 1}{1} \greatcircle{\bx}{\by}{\bz}{red} { 1}{1} \greatcircle{\cx}{\cy}{\cz}{red} { 1}{1} \greatcircle{\px}{\py}{\pz}{blue}{-1}{1} \greatcircle{\qx}{\qy}{\qz}{blue}{ 1}{1} \greatcircle{\rx}{\ry}{\rz}{blue}{-1}{1} % sphere and axes \draw (0,0,0) circle (1 cm); \draw[gray,dashed] (0,0,0) -- (1,0,0); \draw[gray,dashed] (0,0,0) -- (0,1,0); \draw[gray,dashed] (0,0,0) -- (0,0,1); \draw[gray,-latex] (1,0,0) -- (1.5,0,0) node (X) [left] {$x$}; \draw[gray,-latex] (0,1,0) -- (0,1.5,0) node (Y) [right] {$y$}; \draw[gray,-latex] (0,0,1) -- (0,0,1.5) node (Z) [above] {$z$}; % points \fill[blue] (\ax,\ay,\az) circle (0.5pt) node [above] {$A$}; \fill[blue] (\bx,\by,\bz) circle (0.5pt) node [below] {$B$}; \fill[blue] (\cx,\cy,\cz) circle (0.5pt) node [below left] {$C$}; \fill[red] (\px,\py,\pz) circle (0.5pt) node [below right] {$C'$}; \fill[red] (\qx,\qy,\qz) circle (0.5pt) node [left] {$B'$}; \fill[red] (\rx,\ry,\rz) circle (0.5pt) node [above left] {$A'$}; \fill[gray] (0,0,0) circle (0.5pt) node [left] {$O$}; \end{tikzpicture} \end{document}

enter image description here

A little explanation. First, for simplicity I am working with a unit sphere and the data points are provided in spherical coordinates. Then the key here are the poles. Given two points on the sphere, we are looking for the great circle that passes through them, and for the point that would be the north pole if said circumference were the equator. Let A(ax,ay,az) and B(bx,by,bz) be the points, then we can compute the cross product (sorry, there is no MathJax):

            | i  j  k  |
v = A x B = | ax ay az |
            | bx by bz |

The above vector v will give us the direction to find the north pole, and if we normalize it (dividing for its module) the new vector u will point exactly at the pole (C' in my drawing). But that is not all, because this vector u in spherical coordinates will provide the angles for a new canvas in tikz 3d that contains the equator (the great circle which passes through A and B). Due to the perspective we see that circle as an ellipse and its semi-major axis is perpendicular to the projection of u, so then again, the vector can be used to clip the ellipses and separate the visible and non-visible parts.

Juan Castaño
  • 28,426