Calculate rotation matrix corresponding to quaternion
Parameters: | q : 4 element array-like |
---|---|
Returns: | M : (3,3) array
|
Notes
Rotation matrix applies to column vectors, and is applied to the left of coordinate vectors. The algorithm here allows non-unit quaternions.
References
Algorithm from http://en.wikipedia.org/wiki/Rotation_matrix#Quaternion
Examples
>>> import numpy as np
>>> M = quat2mat([1, 0, 0, 0]) # Identity quaternion
>>> np.allclose(M, np.eye(3))
True
>>> M = quat2mat([0, 1, 0, 0]) # 180 degree rotn around axis 0
>>> np.allclose(M, np.diag([1, -1, -1]))
True