1
$\begingroup$

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.

$\endgroup$

2 Answers 2

3
$\begingroup$

Here's a simple algorithm

  1. Define the angles $(\theta_1,\phi_2)$ and $(\theta_2,\phi_1)$

  2. 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}

  1. Build the vector

$$ {\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$

  1. Calculate the angle between ${\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} $$

  1. For $\psi$ in the range $0$ to $\theta$ with steps $\Delta\theta$ calculate the vector

$$ {\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} $$

  1. The set of vectors $\{{\bf x}_\psi\}_\psi$ are uniformly spaced, if you want the angles associated with each point just use the inverse transformation of (1)

enter image description here

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$

$\endgroup$
2
  • $\begingroup$ "the angle between x1 and x2" - that is the central angle, correct? (because I have that one already precalculated directly from the spherical coordinates as $\cos^{-1}{(\cos{\theta_1}\cos{\theta_2} + \sin{\theta_1}\sin{\theta_2}\cos{(\phi_1 - \phi_2}))}$ $\endgroup$
    – Emit Taste
    May 29, 2018 at 11:56
  • $\begingroup$ Well, it is the same thing, since $|{\bf x}_1| = |{\bf x}_2| = 1$ then $$\cos\theta = {\bf x}_1 \cdot {\bf x}_2 = (\sin\theta_1 \cos\phi_1)(\sin\theta_2 \cos\phi_2) + (\sin\theta_1 \cos\sin \phi_1)(\sin\theta_1 \cos\sin \phi_2) + (\cos\theta_1)(\cos\theta_2) = \sin\theta_1 \sin\theta_2 (\cos\phi_1\cos\phi_2 + \sin \theta_1 \sin \theta_2) + \cos\theta_1 \cos\theta_2 = \sin\theta_1\sin\theta_2\cos(\phi_1 - \phi_2) + \cos\theta_1 \cos\theta_2 $$ $\endgroup$
    – caverac
    May 29, 2018 at 12:05
0
$\begingroup$

I simply did sin(1-t)*P1 + sin(t)*P2 for t in range [0, 1]

when P1 and P2 are in cartesian coordinates. I have no idea why it works but it works..

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .