quaternionic.interpolation

slerp

slerp(R1, R2, tau)

Source: quaternionic/interpolation.py

Spherical linear interpolation of quaternions The result of a "slerp" is given by (R2 / R1) ** tau * R1 When tau is 0, this evaluates to R1; when tau is 1, this evaluates to R2; for any other values the result smoothly varies between the two.

Parameters

  • R1: quaternionic.array

    Value at tau == 0

  • R2: quaternionic.array

    Value at tau == 1

  • tau: array_like

    Fractional contribution from R2 relative to R1. It is permissible to use values outside of the range [0, 1], but note that this corresponds to extrapolation. This must broadcast against the result of R2 / R1 — for example, it could be a single number, or it could have the same shape as R1 and R2.

squad

squad(R_in, t_in, t_out)

Source: quaternionic/interpolation.py

Spherical "quadrangular" interpolation of rotors with a cubic spline

Parameters

  • R_in: array of quaternions

    A time-series of rotors (unit quaternions) to be interpolated

  • t_in: array of float

    The times corresponding to R_in

  • t_out: array of float

    The times to which R_in should be interpolated

!!! note This is a smoother way to interpolate a rotation as a function of time than simple slerp. It uses the analog of a cubic spline, except that the interpolant is confined to the rotor manifold in a natural way. Alternative methods involving interpolation of other coordinates on the rotation group or normalization of interpolated values give bad results. The results from this method are fairly natural, and are continuous in first derivatives. The input R_in rotors are assumed to be reasonably continuous (no sign flips), and the input t arrays are assumed to be sorted. No checking is done for either case, and you may get silently bad results if these conditions are violated. The first dimension of R_in must have the same size as t_in, but may have additional axes following.

unflip_rotors

unflip_rotors(R_in, axis=-2, inplace=False)

Source: quaternionic/interpolation.py

Flip signs of quaternions along axis to ensure continuity

Parameters

  • R_in: array_like

    Quaternionic array to modify.

  • axis: optional, int

    Axis along which successive quaternions will be compared. Default value is the second-to-last last axis of the array (the last before the quaternion index).

  • inplace: optional, bool

    If True, modify the data in place without creating a copy; if False (the default), a new array is created and returned.

Returns

  • R_out: array_like

    An array of precisely the same shape as the input array, differing only by factors of precisely -1 in some elements.

!!! note Quaternions form a "double cover" of the rotation group, meaning that if q represents a rotation, then -q represents the same rotation. This is clear from the way a quaternion is used to rotate a vector v: the rotated vector is q * v * q.conjugate(), which is precisely the same as the vector resulting from (-q) * v * (-q).conjugate(). Some ways of constructing quaternions (such as converting from rotation matrices or other representations) can result in unexpected sign choices. For many applications, this will not be a problem. But if, for example, the quaternions need to be interpolated or differentiated, the results may be surprising. This function flips the signs of successive quaternions (along some chosen axis, if relevant), so that successive quaternions are as close as possible while still representing the same rotations. This function works by taking the inner product between successive quaternions (along axis); whenever that product is negative, the sign of the second quaternion is flipped. This does not depend on the quaternions being normalized.