One thing that confuses me much in tikz/pgfplots is the lack of a clear function to draw an arc between two points with a common center of curvature.
As far as I can see the arcs shown here are all either great circles or arcs with constant altitude (parallel to the equator). I took this problem
and thought first about how to draw an arc in general in 3D with a fixed
center of curvature. That is, we need thee points $A$, $B$, and $O$ the
center of curvature of the arc. Initially I wanted to come up with a mathematical equation which does not depends on how my coordinates are set up and I could not find it. I posted the problem in the mathematics site of Stack Exchange and the next day I came up with a solution. The solution of that problem is here:
arc between two points with a center of curvature
Since the maximum number of arguments taken by a "\newcommand" macro is 9,
and I wanted 11 parameters (3 points each with 3 coordinates, number of points in arc, and color)
I created two macros as follows :
\newcommand\pointscolors[2]
{
\def\tempa{#1}
\def\tempb{#2}
}
\newcommand\myarc[9]
{
%center
\def\ox{#1};
\def\oy{#2};
\def\oz{#3};
\coordinate (O) at (\ox,\oy,\oz);
%start
\def\ax{#4};
\def\ay{#5};
\def\az{#6};
\coordinate (A) at (\ax,\ay,\az);
%end
\def\bx{#7}
\def\by{#8}
\def\bz{#9}
\coordinate (B) at (\bx,\by,\bz);
\draw[] (O) --(A) node[anchor=west] {$A$};
\draw[] (O) --(B) node[anchor=west] {$B$};
%\node[anchor=east] at (O) {$O$};
\draw[fill=\tempb] (O) circle (2pt);
\draw[fill=\tempb] (A) circle (2pt);
\draw[fill=\tempb] (B) circle (2pt);
\foreach \t in {0,1,...,\tempa}
{%
% cosine and sine
% paramter s in [0,1]
\pgfmathsetmacro\scl{divide(1,\tempa}
\pgfmathsetmacro\s{\scl*\t}
% shift coordinates
\pgfmathsetmacro\aox{\ax-\ox}
\pgfmathsetmacro\aoy{\ay-\oy}
\pgfmathsetmacro\aoz{\az-\oz}
\pgfmathsetmacro\boxo{\bx-\ox}
\pgfmathsetmacro\boy{\by-\oy}
\pgfmathsetmacro\boz{\bz-\oz}
\pgfmathsetmacro\bax{\bx-\ax}
\pgfmathsetmacro\bay{\by-\ay}
\pgfmathsetmacro\baz{\bz-\az}
\coordinate (AO) at (\aox, \aoy, \aoz );
\coordinate (BO) at (\boxo, \boy, \boz );
% find radius r
\pgfmathsetmacro\r{sqrt(\aox*\aox+\aoy*\aoy+\aoz*\aoz)}
% find p
\pgfmathsetmacro\px{\aox+\s*(\boxo-\aox}
\pgfmathsetmacro\py{\aoy+\s*(\boy-\aoy)}
\pgfmathsetmacro\pz{\aoz+\s*(\boz-\aoz)}
% find ||p||
\pgfmathsetmacro\p{sqrt(\px*\px + \py*\py + \pz*\pz)}
% find ||u||
\pgfmathsetmacro\ux{divide(\px,\p)}
\pgfmathsetmacro\uy{divide(\py,\p)}
\pgfmathsetmacro\uz{divide(\pz,\p)}
% find the solution x
\pgfmathsetmacro\xx{\r*\ux}
\pgfmathsetmacro\xy{\r*\uy}
\pgfmathsetmacro\xz{\r*\uz}
% add origin
\pgfmathsetmacro\x{\xx + \ox}
\pgfmathsetmacro\y{\xy + \oy}
\pgfmathsetmacro\z{\xz + \oz}
\coordinate (X) at (\x,\y, \z);
\node[color=\tempb] at (X) {.};
}
}
Note that this macro does what my equations in the
find arc between two tips of vectors in 3D
suggests.
The macro goes into the LaTeX preamble. Then in the main document
I used a test to call it. Here is the test:
\tdplotsetmaincoords{10}{100}
\begin{tikzpicture}[scale=1.0, tdplot_main_coords]
% axes and origin of coordinate system
\coordinate (Xa) at (4,0,0);
\coordinate (Ya) at (0,4,0);
\coordinate (Za) at (0,0,22);
\coordinate (C) at (0,0,0);
% draw sphere
\def\R{4};
\fill[ball color=white!10] (C) circle (\R); % 3D lighting effect
% set color and number of points
\pointscolors[100][red];
% call macro "myarc"
\myarc{0}{0}{3}{3}{1}{0.45}{-3}{1}{0.45}
% draw coordinate axes
\draw[-latex] (C)--(Xa) node[yshift=-2mm] {$ X$};
\draw[-latex] (C)--(Ya) node[anchor=west] {$Y$};
\draw[-latex] (C)--(Za) node[anchor=south] {$Z$};
\end{tikzpicture}
Then the figure is here:

I created another plot to help explain why the shortest path between two points in a sphere is along a great circle. This was motivated by the
stack exchange post:
shortest path in a sphere
The figure for that post is next.

and the code for it is here:
\tdplotsetmaincoords{25}{60}
\begin{tikzpicture}[scale=1.0, tdplot_main_coords]
\coordinate (Xa) at (4,0,0);
\coordinate (Ya) at (0,4,0);
\coordinate (Za) at (0,0,8);
\coordinate (C) at (0,0,0);
% draw sphere
\def\R{4};
\fill[ball color=white!10] (C) circle (\R); % 3D lighting effect
%\foreach \t in {0,4,1}
%{
%\myarc{0}{0}{\t}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
%}
\pointscolors{200}{green};
\myarc{0}{0}{0}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
\pointscolors{200}{blue};
\myarc{0}{0}{0.5}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
\pointscolors{200}{red};
\myarc{0}{0}{1.0}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
\pointscolors{200}{brown};
\myarc{0}{0}{1.5}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
\pointscolors{200}{orange};
\myarc{0}{0}{2.0}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
\pointscolors{200}{orange};
%\myarc{0}{0}{2.645751311064591}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591};
%\pointscolors{100}{yellow};
% draw coordinate axes
\draw[-latex] (C)--(Xa) node[yshift=-2mm] {$ X$};
\draw[-latex] (C)--(Ya) node[anchor=west] {$Y$};
\draw[-latex] (C)--(Za) node[anchor=south] {$Z$};
\end{tikzpicture}
The argument for the shortest path is that I am using 200 points on each arc. The green arc corresponds to a great circle and the points are all squeezed. The other arcs grow in length as the center of curvature moves up from the origin.
The plot of points by using "node" is no elegant at all. The number of points is hard coded as well. I do not have the high level specifications to develop low level code.
If anyone can help to improve this
function this could be very beneficial for all LaTeX community..
Thanks.
\documentclass
and the appropriate packages so that those trying to help don't have to recreate it. This is especially important withtikz
as there are numerous libraries.\tikzset{POQ/.estyle={cm={..,..,..,..,(0,0)}}}
but the problem is to find ..,..,..,.., !!