interpolate¶
Overview
rowan.interpolate.slerp |
Spherical linear interpolation between p and q. |
rowan.interpolate.slerp_prime |
Compute the derivative of slerp. |
rowan.interpolate.squad |
Cubically interpolate between p and q. |
Details
Interpolate between pairs of quaternions.
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)¶ Spherical linear interpolation between p and q.
The slerp formula can be easily expressed in terms of the quaternion exponential (see
rowan.exp()
).Parameters: - q0 ((…, 4)
numpy.ndarray
) – First array of quaternions. - q1 ((…, 4)
numpy.ndarray
) – Second array of quaternions. - t ((…)
numpy.ndarray
) – 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: Interpolations between p
andq
.Return type: (…, 4) numpy.ndarray
Example:
>>> import numpy as np >>> rowan.interpolate.slerp( ... [[1, 0, 0, 0]], [[np.sqrt(2)/2, np.sqrt(2)/2, 0, 0]], 0.5) array([[0.92387953, 0.38268343, 0. , 0. ]])
- q0 ((…, 4)
-
rowan.interpolate.
slerp_prime
(q0, q1, t, ensure_shortest=True)¶ Compute the derivative of slerp.
Parameters: - q0 ((…, 4)
numpy.ndarray
) – First set of quaternions. - q1 ((…, 4)
numpy.ndarray
) – Second set of quaternions. - t ((…)
numpy.ndarray
) – Interpolation parameter \(\in [0, 1]\) - ensure_shortest (bool) – Flip quaternions to ensure we traverse the geodesic in the shorter (\(<180^{\circ}\)) direction
Returns: The derivative of the interpolations between
p
andq
.Return type: (…, 4)
numpy.ndarray
Example:
import numpy as np q_slerp_prime rowan.interpolate.slerp_prime( [[1, 0, 0, 0]], [[np.sqrt(2)/2, np.sqrt(2)/2, 0, 0]], 0.5)
- q0 ((…, 4)
-
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 as originally derived in [Shoemake85]:
\[\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}\][Shoemake85] Ken Shoemake. Animating rotation with quaternion curves. SIGGRAPH Comput. Graph., 19(3):245-254, July 1985. Parameters: - p ((…, 4)
numpy.ndarray
) – First endpoint of interpolation. - a ((…, 4)
numpy.ndarray
) – First control point of interpolation. - b ((…, 4)
numpy.ndarray
) – Second control point of interpolation. - q ((…, 4)
numpy.ndarray
) – Second endpoint of interpolation. - t ((…)
numpy.ndarray
) – Interpolation parameter \(t \in [0, 1]\).
Returns: Interpolations between
p
andq
.Return type: (…, 4)
numpy.ndarray
Example:
>>> import numpy as np >>> rowan.interpolate.squad( ... [1, 0, 0, 0], [np.sqrt(2)/2, np.sqrt(2)/2, 0, 0], ... [0, np.sqrt(2)/2, np.sqrt(2)/2, 0], ... [0, 0, np.sqrt(2)/2, np.sqrt(2)/2], 0.5) array([[0.64550177, 0.47254009, 0.52564058, 0.28937053]])
- p ((…, 4)