psychopy.tools.mathtools.invertQuat

psychopy.tools.mathtools.invertQuat(q, out=None, dtype=None)[source]

Get the multiplicative inverse of a quaternion.

This gives a quaternion which rotates in the opposite direction with equal magnitude. Multiplying a quaternion by its inverse returns an identity quaternion as both orientations cancel out.

Parameters:
  • q (ndarray, list, or tuple of float) – Quaternion to invert in form [x, y, z, w] where w is real and x, y, z are imaginary components. If q is 2D (Nx4), each row is treated as a separate quaternion and inverted.

  • out (ndarray, optional) – Optional output array. Must be same shape and dtype as the expected output if out was not specified.

  • dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.

Returns:

Inverse of quaternion q.

Return type:

ndarray

Examples

Show that multiplying a quaternion by its inverse returns an identity quaternion where [x=0, y=0, z=0, w=1]:

angle = 90.0
axis = [0., 0., -1.]
q = quatFromAxisAngle(axis, angle, degrees=True)
qinv = invertQuat(q)
qr = multQuat(q, qinv)
qi = np.array([0., 0., 0., 1.])  # identity quaternion
print(np.allclose(qi, qr))   # True

Notes

  • Quaternions are normalized prior to inverting.


Back to top