Convert rotation matrices to unit quaternion(s).
[q0,q1,q2,q3] = rotmat2quat(R) q = rotmat2quat(R)
Computes the unit quaternion(s) corresponding to the input rotation matrices. The rotation matrices are given as an array R
of size 3x3xN. The corresponding unit quaternion(s) are returned as a 4xN array or using the individual components q0
, q1
, q2
, q3
(each of size 1xN).
Note that rotmat2quat
is vectorized and will accept arrays of rotation matrices of size 3x3xNxMx... with an arbitrary number of dimensions, in which case the unit quaternions will be returned as an array of size 3x3xNxMx... .
For details about rotation matrices and orientations, see the page on relative orientations.
Let's create an arbitrary rotation matrix using Euler angles.
ang = [34 72 -143]*pi/180; R = erot(ang)
R = 0.1319 -0.6369 0.7595 0.6008 -0.5581 -0.5724 0.7885 0.5318 0.3090
Taking this rotation matrix, we compute the unit quaternion.
q = rotmat2quat(R)
q = 0.4698 0.5876 -0.0154 0.6586
Now, feeding this quaternion into quat2rotmat
,
we get back the original rotation matrix.
quat2rotmat(q)
ans = 0.1319 -0.6369 0.7595 0.6008 -0.5581 -0.5724 0.7885 0.5318 0.3090
quat2rotmat, quat2euler, euler2quat, quatvecmult