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
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) np.array) – First array of quaternions.
- q1 ((..,4) np.array) – Second array 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: Array of shape (…, 4) 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]]) 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 of shape (…, 4) 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]]) 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 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) np.array) – First endpoint of interpolation.
- a ((..,4) np.array) – First control point of interpolation.
- b ((..,4) np.array) – Second control point of interpolation.
- q ((..,4) np.array) – Second endpoint of interpolation.
- t ((..) np.array) – Interpolation parameter \(t \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]]) q2 = np.array([[0, np.sqrt(2)/2, np.sqrt(2)/2, 0]]) q3 = np.array([[0, 0, np.sqrt(2)/2, np.sqrt(2)/2]]) squad(q0, q1, q2, q3, 0.5)