I have two points on a unit sphere, given as tuples $(\theta, \phi)$. I need an efficient way to interpolate them, for example given $t$ between zero and one, to generate a point that lies (on the unit sphere) between the two points, where $t = 0$ would give the first point, $t = 1$ would give the second point, and $t = 0.5$ would give a point that is exactly in the middle.
I read about Slerp, but I don't know how to apply the quaternions math to the spherical coordinates.
(If the two points are antipodal, let the result be random)
It seems to be very similar to this question/answer, only that I use spherical coordinates instead of latitude/longitude.
Best Answer
Here's a simple algorithm
Define the angles $(\theta_1,\phi_2)$ and $(\theta_2,\phi_1)$
Transform these into cartesian vectors ${\bf x}_1$ and ${\bf x}_2$ using
\begin{eqnarray} x &=& \sin\theta\cos\phi \\ y &=& \sin\theta\sin\phi \\ z &=& \cos\theta\tag{1} \end{eqnarray}
$$ {\bf k} = \frac{{\bf x}_1 \times {\bf x}_2}{|{\bf x}_1 \times {\bf x}_2|} \tag{2} $$
This is a vector perpendicular to the plane spanned by ${\bf x}_1$ and ${\bf x}_2$
$$ \theta = \cos^{-1}\left(\frac{{\bf x}_1 \cdot {\bf x}_2}{|{\bf x}_1||{\bf x}_2|}\right) \tag{3} $$
$$ {\displaystyle \mathbf {x}_\psi =\mathbf {x}_1 \cos \psi +(\mathbf {k} \times \mathbf {x}_1 )\sin \psi +\mathbf {k} ~(\mathbf {k} \cdot \mathbf {x}_1 )(1-\cos \psi )} \tag{4} $$
This is an example using $(\theta_1,\phi_1) = (0.4, 1.0)$, $(\theta_2,\phi_2) = (2.0, 1.6)$ and $\Delta \theta = 0.1$