tikz add tag
Anonymous 1123
I have a list of a squares on sphere has the equation

`(x-1)^2 + (y-3)^2 + (z-5)^2 =15^2`.
```
{{{-13, -3, 1}, {-10, 12, 5}, {-1, 7, 17}, {-4, -8, 13}}, {{-13, -3, 1}, {-4, 12, 13}, {15, 7, 5}, {6, -8, -7}}, {{-13, -3, 5}, {-10, 12, 1}, {-1, 7, -11}, {-4, -8, -7}}, {{-13, -3, 5}, {-9, 12, 8}, {3, 7, 17}, {-1, -8, 14}}, {{-13, -3, 5}, {-4, 12, -7}, {15, 7, 1}, {6, -8, 13}}, {{-13, 0, -2}, {-10, 4, 13}, {-1, 16, 8}, {-4, 12, -7}}, {{-13, 0, -2}, {-4, 12, 13}, {15, 4, 8}, {6, -8, -7}}, {{-13, 0, 8}, {-10, 4, -7}, {-1, 16, -2}, {-4, 12, 13}}, {{-13, 0, 8}, {-4, 12, -7}, {15, 4, -2}, {6, -8, 13}}, {{-13, 4, -2}, {-10, 0, 13}, {-1, -12, 8}, {-4, -8, -7}}, {{-13, 4, -2}, {-4, -8, 13}, {15, 0, 8}, {6, 12, -7}}, {{-13, 4, 8}, {-10, 0, -7}, {-1, -12, -2}, {-4, -8, 13}}, {{-13, 4, 8}, {-4, -8, -7}, {15, 0, -2}, {6, 12, 13}}, {{-13, 7, 1}, {-10, -8, 5}, {-1, -3, 17}, {-4, 12, 13}}, {{-13, 7, 1}, {-4, -8, 13}, {15, -3, 5}, {6, 12, -7}}, {{-13, 7, 5}, {-10, -8, 1}, {-1, -3, -11}, {-4, 12, -7}}, {{-13, 7, 5}, {-9, -8, 8}, {3, -3, 17}, {-1, 12, 14}}, {{-13, 7, 5}, {-4, -8, -7}, {15, -3, 1}, {6, 12, 13}}, {{-10, 0, -7}, {-1, -12, 8}, {12, 4, 13}, {3, 16, -2}}, {{-10, 0, 13}, {-1, -12, -2}, {12, 4, -7}, {3, 16, 8}}, {{-10, 4, -7}, {-1, 16, 8}, {12, 0, 13}, {3, -12, -2}}, {{-10, 4, 13}, {-1, 16, -2}, {12, 0, -7}, {3, -12, 8}}, {{-9, -8, -2}, {-4, 0, 17}, {11, 12, 8}, {6, 4, -11}}, {{-9, -8, -2}, {-1, -3, 17}, {11, 12, 8}, {3, 7, -11}}, {{-9, -8, 8}, {-4, 0, -11}, {11, 12, -2}, {6, 4, 17}}, {{-9, -8, 8}, {-4, 4, 17}, {11, 0, 14}, {6, -12, 5}}, {{-9, -8, 8}, {-1, -3, -11}, {11, 12, -2}, {3, 7, 17}}, {{-9, -3, -7}, {-4, 16, 1}, {11, 7, 13}, {6, -12, 5}}, {{-9, -3, -7}, {-1, 16, -2}, {11, 7, 13}, {3, -12, 8}}, {{-9, -3, 13}, {-4, 16, 5}, {11, 7, -7}, {6, -12, 1}}, {{-9, -3, 13}, {-1, 16, 8}, {11, 7, -7}, {3, -12, -2}}, {{-9, 0, -8}, {-4, 16, 5}, {11, 4, 14}, {6, -12, 1}}, {{-9, 0, 14}, {-4, -12, 5}, {11, -8, 8}, {6, 4, 17}}, {{-9, 0, 14}, {-4, 16, 1}, {11, 4, -8}, {6, -12, 5}}, {{-9, 4, -8}, {-4, -12, 5}, {11, 0, 14}, {6, 16, 1}}, {{-9, 4, -8}, {-4, 16, 1}, {11, 12, -2}, {6, 0, -11}}, {{-9, 4, 14}, {-4, -12, 1}, {11, 0, -8}, {6, 16, 5}}, {{-9, 4, 14}, {-4, 16, 5}, {11, 12, 8}, {6, 0, 17}}, {{-9, 7, -7}, {-4, -12, 1}, {11, -3, 13}, {6, 16, 5}}, {{-9, 7, -7}, {-4, 16, 5}, {11, 13, 1}, {6, 4, -11}}, {{-9, 7, -7}, {-1, -12, -2}, {11, -3, 13}, {3, 16, 8}}, {{-9, 7, 13}, {-4, -12, 5}, {11, -3, -7}, {6, 16, 1}}, {{-9, 7, 13}, {-1, -12, 8}, {11, -3, -7}, {3, 16, -2}}, {{-9, 12, -2}, {-4, 0, -11}, {11, 4, -8}, {6, 16, 1}}, {{-9, 12, -2}, {-4, 4, 17}, {11, -8, 8}, {6, 0, -11}}, {{-9, 12, -2}, {-1, 7, 17}, {11, -8, 8}, {3, -3, -11}}, {{-9, 12, 8}, {-4, 0, 17}, {11, 4, 14}, {6, 16, 5}}, {{-9, 12, 8}, {-4, 4, -11}, {11, -8, -2}, {6, 0, 17}}, {{-9, 12, 8}, {-1, 7, -11}, {11, -8, -2}, {3, -3, 17}}, {{-9, 13, 1}, {-4, 4, -11}, {11, 7, -7}, {6, 16, 5}}, {{-1, -12, -2}, {3, -9, 13}, {15, 0, 8}, {11, -3, -7}}, {{-1, -12, 8}, {3, -9, -7}, {15, 0, -2}, {11, -3, 13}}, {{-1, -3, 17}, {3, 12, 14}, {15, 7, 5}, {11, -8, 8}}, {{-1, 7, 17}, {3, -8, 14}, {15, -3, 5}, {11, 12, 8}}, {{3, -12, -2}, {6, -8, 13}, {15, 4, 8}, {12, 0, -7}}, {{3, -12, 8}, {6, -8, -7}, {15, 4, -2}, {12, 0, 13}}}
```
How to draw a square or some squares from a list of squares on sphere?
For exmaple, the first square 

`{{-13, -3, 1}, {-10, 12, 5}, {-1, 7, 17}, {-4, -8, 13}}`
Top Answer
user 3.14159
Here is a lengthy answer that constructs great circles between the corners of the 4-gon. (Whether or not one should call it square depends on how one wants to define a square.)
```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\makeatletter
% \pgfmathdeclarefunction{isfore}{3}{%
% \begingroup%
% \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
% \pgfmathparse{%
% sign(((\the\pgf@yx)*(\the\pgf@zy)-(\the\pgf@yy)*(\the\pgf@zx))*(#1)+
% ((\the\pgf@zx)*(\the\pgf@xy)-(\the\pgf@xx)*(\the\pgf@zy))*(#2)+
% ((\the\pgf@xx)*(\the\pgf@yy)-(\the\pgf@yx)*(\the\pgf@xy))*(#3))}%
% \pgfmathsmuggle\pgfmathresult\endgroup%
% }%
\tikzset{3d/great circle arc/.cd,
	theta1/.initial=0,phi1/.initial=0,theta2/.initial=0,phi2/.initial=30,
	r/.initial=R,fore/.style={draw=white,semithick},back/.style={draw=gray,very thin}}
	
\tikzset{pics/3d/great circle arc/.style={code={%
\tikzset{3d/great circle arc/.cd,#1}%
\def\pv##1{\pgfkeysvalueof{/tikz/3d/great circle arc/##1}}%
 % Cartesian coordinates of the first point (A) 
\pgfmathsetmacro\pgfutil@tempAx{\pv{r}*cos(\pv{theta1})*cos(\pv{phi1})}%
\pgfmathsetmacro\pgfutil@tempAy{\pv{r}*cos(\pv{theta1})*sin(\pv{phi1})}%
\pgfmathsetmacro\pgfutil@tempAz{\pv{r}*sin(\pv{theta1})}%
 % Cartesian coordinates of the second point (B) 
\pgfmathsetmacro\pgfutil@tempBx{\pv{r}*cos(\pv{theta2})*cos(\pv{phi2})}%
\pgfmathsetmacro\pgfutil@tempBy{\pv{r}*cos(\pv{theta2})*sin(\pv{phi2})}%
\pgfmathsetmacro\pgfutil@tempBz{\pv{r}*sin(\pv{theta2})}%
 % cross product C=AxB 
\pgfmathsetmacro@td@FPU\pgfutil@tempCx{(\pgfutil@tempAy)*(\pgfutil@tempBz)-(\pgfutil@tempBy)*(\pgfutil@tempAz)}%
\pgfmathsetmacro@td@FPU\pgfutil@tempCy{(\pgfutil@tempAz)*(\pgfutil@tempBx)-(\pgfutil@tempBz)*(\pgfutil@tempAx)}%
\pgfmathsetmacro@td@FPU\pgfutil@tempCz{(\pgfutil@tempAx)*(\pgfutil@tempBy)-(\pgfutil@tempBx)*(\pgfutil@tempAy)}%
 % normalize C to have length r
\pgfmathsetmacro@td@FPU\pgfutil@tempa{sqrt((\pgfutil@tempCx)*(\pgfutil@tempCx)+(\pgfutil@tempCy)*(\pgfutil@tempCy)+(\pgfutil@tempCz)*(\pgfutil@tempCz))/\pv{r}}%
\pgfmathsetmacro@td@FPU\pgfutil@tempCx{\pgfutil@tempCx/\pgfutil@tempa}%
\pgfmathsetmacro@td@FPU\pgfutil@tempCy{\pgfutil@tempCy/\pgfutil@tempa}%
\pgfmathsetmacro@td@FPU\pgfutil@tempCz{\pgfutil@tempCz/\pgfutil@tempa}%
 % angle between A and B
\pgfmathsetmacro@td@FPU\pgfutil@tempAdotB{((\pgfutil@tempAx)*(\pgfutil@tempBx)+
	(\pgfutil@tempAy)*(\pgfutil@tempBy)+(\pgfutil@tempAz)*(\pgfutil@tempBz))/(\pv{r}*\pv{r})}% 
\pgfmathsetmacro@td@FPU\pgfutil@tempangle{acos(\pgfutil@tempAdotB)}%	
 % cross product D=AxC
\pgfmathsetmacro@td@FPU\pgfutil@tempDx{(\pgfutil@tempAy)*(\pgfutil@tempCz)-(\pgfutil@tempCy)*(\pgfutil@tempAz)}%
\pgfmathsetmacro@td@FPU\pgfutil@tempDy{(\pgfutil@tempAz)*(\pgfutil@tempCx)-(\pgfutil@tempCz)*(\pgfutil@tempAx)}%
\pgfmathsetmacro@td@FPU\pgfutil@tempDz{(\pgfutil@tempAx)*(\pgfutil@tempCy)-(\pgfutil@tempCx)*(\pgfutil@tempAy)}%
\pgfmathsetmacro@td@FPU\pgfutil@tempa{sqrt((\pgfutil@tempDx)*(\pgfutil@tempDx)+(\pgfutil@tempDy)*(\pgfutil@tempDy)+(\pgfutil@tempDz)*(\pgfutil@tempDz))/\pv{r}}%
\pgfmathsetmacro@td@FPU\pgfutil@tempDx{\pgfutil@tempDx/\pgfutil@tempa}%
\pgfmathsetmacro@td@FPU\pgfutil@tempDy{\pgfutil@tempDy/\pgfutil@tempa}%
\pgfmathsetmacro@td@FPU\pgfutil@tempDz{\pgfutil@tempDz/\pgfutil@tempa}%
 %\typeout{A=(\pgfutil@tempAx,\pgfutil@tempAy,\pgfutil@tempAz),B=(\pgfutil@tempBx,\pgfutil@tempBy,\pgfutil@tempBz),C=(\pgfutil@tempCx,\pgfutil@tempCy,\pgfutil@tempCz)}
 %\typeout{\pgfutil@tempAdotB,\pgfutil@tempangle}
\edef\pgfutil@tempa{0}%
\edef\pgfutil@temphasvis{0}%
\edef\pgfutil@temphashid{0}%
\pgfmathsetmacro{\pgfutil@oldsd}{screendepth(\pgfutil@tempAx,\pgfutil@tempAy,\pgfutil@tempAz)}%
\ifdim\pgfutil@oldsd pt<0pt\relax
\edef\pgfutil@templsthidcoords{(\pgfutil@tempAx,\pgfutil@tempAy,\pgfutil@tempAz)}%
\edef\pgfutil@templstviscoords{}
\edef\pgfutil@temphashid{1}%
\edef\pgfutil@tempprevious{0}%
\else
\edef\pgfutil@templstviscoords{(\pgfutil@tempAx,\pgfutil@tempAy,\pgfutil@tempAz)}%
\edef\pgfutil@templsthidcoords{}%
\edef\pgfutil@temphasvis{1}%
\edef\pgfutil@tempprevious{1}%
\fi
\pgfmathtruncatemacro\pgfutil@tempb{acos(\pgfutil@tempAdotB)}%
\pgfmathtruncatemacro\pgfutil@tempc{sign(\pgfutil@tempb)}%
\loop
\pgfmathsetmacro{\tmpx}{cos(\pgfutil@tempa)*\pgfutil@tempAx-\pgfutil@tempc*sin(\pgfutil@tempa)*\pgfutil@tempDx}%
\pgfmathsetmacro{\tmpy}{cos(\pgfutil@tempa)*\pgfutil@tempAy-\pgfutil@tempc*sin(\pgfutil@tempa)*\pgfutil@tempDy}%
\pgfmathsetmacro{\tmpz}{cos(\pgfutil@tempa)*\pgfutil@tempAz-\pgfutil@tempc*sin(\pgfutil@tempa)*\pgfutil@tempDz}%
\pgfmathsetmacro{\pgfutil@tempsd}{screendepth(\tmpx,\tmpy,\tmpz)}%
\pgfmathtruncatemacro{\pgfutil@tempd}{sign(\pgfutil@tempsd)}%
\typeout{\pgfutil@tempsd:\pgfutil@tempd}%
\ifnum\pgfutil@tempd=-1\relax
\ifnum\pgfutil@tempprevious=1\relax
\else
\fi
\edef\pgfutil@templsthidcoords{\pgfutil@templsthidcoords\space(\tmpx,\tmpy,\tmpz)}%
\edef\pgfutil@temphashid{1}%
\else
\edef\pgfutil@templstviscoords{\pgfutil@templstviscoords\space(\tmpx,\tmpy,\tmpz)}%
\edef\pgfutil@temphasvis{1}%
\fi
\edef\pgfutil@tempa{\the\numexpr\pgfutil@tempa+1}%
\let\pgfutil@oldsd\pgfutil@tempsd
\ifnum\pgfutil@tempa<\the\numexpr\pgfutil@tempc*\pgfutil@tempb\relax
\repeat
\pgfmathsetmacro{\pgfutil@tempsd}{screendepth(\pgfutil@tempBx,\pgfutil@tempBy,\pgfutil@tempBz)}%
\pgfmathtruncatemacro{\pgfutil@tempd}{sign(\pgfutil@tempsd)}%
%\pgfmathtruncatemacro{\pgfutil@tempd}{isfore(\pgfutil@tempBx,\pgfutil@tempBy,\pgfutil@tempBz)}%
\ifnum\pgfutil@tempd=-1\relax
\edef\pgfutil@templsthidcoords{\pgfutil@templsthidcoords\space(\pgfutil@tempBx,\pgfutil@tempBy,\pgfutil@tempBz)}%
\edef\pgfutil@temphashid{1}%
\else
\edef\pgfutil@templstviscoords{\pgfutil@templstviscoords\space(\pgfutil@tempBx,\pgfutil@tempBy,\pgfutil@tempBz)}%
\edef\pgfutil@temphasvis{1}%
\fi
\ifnum\pgfutil@temphashid=1%
\typeout{hid:\pgfutil@templsthidcoords}%
\draw[3d/hidden] foreach \pgfutil@tempx in {\pgfutil@templsthidcoords}
{plot coordinates {\pgfutil@tempx}};%
\fi
\ifnum\pgfutil@temphasvis=1%
\typeout{vis:\pgfutil@templstviscoords}%
\draw[3d/visible] foreach \pgfutil@tempx in {\pgfutil@templstviscoords}
{plot coordinates {\pgfutil@tempx}};%
\fi
}}}
\makeatother
\begin{document}
\foreach \Angle in {5} %{5,15,...,355}
{\begin{tikzpicture}[declare function={R=15;},scale=0.3]
\begin{scope}[3d/install view={phi=\Angle,theta=70}]
 \path (2,4,6) coordinate (O')
 	(-12,-1,4) coordinate (A) (-9,14,8) coordinate (B) 
 	(0,9,20) coordinate (C) (-3,-6,16) coordinate (D);
 \path[3d/screen coords,shift={(O')},
 	use as bounding box] (-R-1,-R-1) rectangle (R+1,R+1);	
 \shade[3d/screen coords,ball color = black!80,
 transform canvas={rotate around={-35:(O')}}]  
 (O') circle[radius=R];
 \path foreach \X in {A,B,C,D} 
 {[3d coordinate={(\X')=(\X)-(O')}]%(\X) node[circle,draw,blue]{}
 };
 \tikzset{get spherical angles/.code={%
 \expandafter\pgfmathsetmacro\csname lat##1\endcsname{asin(TD("(##1')o(0,0,1)")/R)}
 \expandafter\pgfmathsetmacro\csname az##1\endcsname{atan2(TD("(##1')o(0,1,0)"),TD("(##1')o(1,0,0)"))}}}
 \tikzset{get spherical angles/.list={A,B,C,D}}
 \path[shift={(O')},transform shape,
 	3d/visible/.append style={yellow},
	3d/hidden/.append style={yellow}] 
  pic{3d/great circle arc={theta1={\latA},phi1={\azA},theta2={\latB},phi2={\azB}}}
  pic{3d/great circle arc={theta1={\latB},phi1={\azB},theta2={\latC},phi2={\azC}}}
  pic{3d/great circle arc={theta1={\latC},phi1={\azC},theta2={\latD},phi2={\azD}}}
  pic{3d/great circle arc={theta1={\latD},phi1={\azD},theta2={\latA},phi2={\azA}}};
 %
\end{scope}
\end{tikzpicture}}
\end{document}
```
![Screen Shot 2021-02-11 at 8.35.24 PM.png](/image?hash=0436be25ffabedcc4ebfab91deb401632ef53c9b866b6ca1a5d636f96dde2211)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.