interpolate

Overview

rowan.interpolate.slerp Linearly interpolate between p and q.
rowan.interpolate.slerp_prime Compute the derivative of slerp.
rowan.interpolate.squad Cubically interpolate between p and q.

Details

The rowan package provides a simple interface to slerp, the standard method of quaternion interpolation for two quaternions.

rowan.interpolate.slerp(q0, q1, t, ensure_shortest=True)

Linearly interpolate between p and q.

The slerp formula can be easily expressed in terms of the quaternion exponential (see rowan.exp()).

Parameters:
  • q0 ((..,4) np.array) – First set of quaternions
  • q1 ((..,4) np.array) – Second set of quaternions
  • t ((..) np.array) – Interpolation parameter \(\in [0, 1]\)
  • ensure_shortest (bool) – Flip quaternions to ensure we traverse the geodesic in the shorter (\(<180^{\circ}\)) direction

Note

Given inputs such that \(t\notin [0, 1]\), the values outside the range are simply assumed to be 0 or 1 (depending on which side of the interval they fall on).

Returns:An array containing the element-wise interpolations between p and q.

Example:

q0 = np.array([[1, 0, 0, 0]])
q1 = np.array([[np.sqrt(2)/2, np.sqrt(2)/2, 0, 0]])
interpolate.slerp(q0, q1, 0.5)
rowan.interpolate.slerp_prime(q0, q1, t, ensure_shortest=True)

Compute the derivative of slerp.

Parameters:
  • q0 ((..,4) np.array) – First set of quaternions
  • q1 ((..,4) np.array) – Second set of quaternions
  • t ((..) np.array) – Interpolation parameter \(\in [0, 1]\)
  • ensure_shortest (bool) – Flip quaternions to ensure we traverse the geodesic in the shorter (\(<180^{\circ}\)) direction
Returns:

An array containing the element-wise derivatives of interpolations between p and q.

Example:

q0 = np.array([[1, 0, 0, 0]])
q1 = np.array([[np.sqrt(2)/2, np.sqrt(2)/2, 0, 0]])
interpolate.slerp_prime(q0, q1, 0.5)
rowan.interpolate.squad(p, a, b, q, t)

Cubically interpolate between p and q.

The SQUAD formula is just a repeated application of Slerp between multiple quaternions:

\[\begin{equation} \textrm{squad}(p, a, b, q, t) = \textrm{slerp}(p, q, t) \left(\textrm{slerp}(p, q, t)^{-1}\textrm{slerp}(a, b, t) \right)^{2t(1-t)} \end{equation}\]
Parameters:
  • p ((..,4) np.array) – First endpoint of interpolation
  • q ((..,4) np.array) – Second endpoint of interpolation
  • t ((..) np.array) – Interpolation parameter \(\in [0, 1]\)
Returns:

An array containing the element-wise interpolations between p and q.

Example:

q0 = np.array([[1, 0, 0, 0]])
q1 = np.array([[np.sqrt(2)/2, np.sqrt(2)/2, 0, 0]])
interpolate.squad(q0, q1, 0.5)