mdtraj.utils.rotation_matrix_from_quaternion

mdtraj.utils.rotation_matrix_from_quaternion(q)

Compute a 3x3 rotation matrix from a given quaternion (4-vector).

Parameters:

q : np.ndarray, size=(…, 4)

Quaternion or array of quaternions (need not be normalized, zero norm OK)

Returns:

Rq : np.ndarray, size=(…, 3, 3)

Orthogonal rotation matrices corresponding to quaternion(s) q. Given, for example, an input shape of (m, 4), Rq will have shape (m, 3, 3).

References

[R7474]http://en.wikipedia.org/wiki/Rotation_matrix#Quaternion

Examples

>>> q = np.array([0.1, 0.2, 0.3, -0.4])
>>> Rq = rotation_matrix_from_quaternion(q)