Convert rotation matrix to quaternion
Convert Rotation Matrix to Quaternion
rotm = [0 0 1; 0 1 0; -1 0 0]; quat = rotm2quat(rotm)
quat = 1×4 0.7071 0 0.7071 0
rotm — Rotation matrix
Rotation matrix, specified as a 3-by-3-by-n matrix containing n rotation matrices. Each rotation matrix has a size of 3-by-3 and is orthonormal. The input rotation matrix must be in the premultiply form for rotations.
Rotation matrices that are slightly non-orthonormal can give complex outputs. Consider validating your matrix before inputting to the function.
[0 0 1; 0 1 0; -1 0 0]
quat — Unit quaternion
Unit quaternion, returned as an n-by-4 matrix containing n quaternions. Each quaternion, one per row, is of the form q = [w x y z], with w as the scalar number.
[0.7071 0.7071 0 0]
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Introduced in R2015a