C ++ / Matlab native quaternion criterion and matrix matrices

I noticed that there is a difference in Eigen C ++ and Matlab when computing with quaternions. In Eigen C ++ the code is

Eigen::Quaterniond q;
q.x() = 0.270598;
q.y() = 0.653281;
q.z() = -0.270598;
q.w() = 0.653281;

Eigen::Matrix3d R = q.normalized().toRotationMatrix();
std::cout << "R=" << std::endl << R << std::endl;

      

gives the rotation matrix:

R=
-2.22045e-16     0.707107     0.707107
           0     0.707107    -0.707107
          -1            0 -2.22045e-16

      

In Matlab (which uses wxyz), however, I get the following output:

q =

    0.6533    0.2706    0.6533   -0.2706

>> quat2dcm(q)

ans =
   -0.0000         0   -1.0000
    0.7071    0.7072         0
    0.7072   -0.7071   -0.0000

      

which is transposition! Can someone explain to me what is going on? I have verified that wxyz's positions are correct.

thank

+3


source to share


1 answer


With Matlab, you compute the cosine matrix . It is indeed a rotation matrix like the one you calculate with Eigen C ++ and as such is also unitary (all rows and all columns are norm 1 and form either a perpendicular set of vectors).

So, it so happened that the inverse unit of a unitary matrix is ​​equal to its conjugate transposition (*), i.e.

U * U = UU * = I



In other words, what should be happening is that the Matlab convention is the opposite of the C ++ Eigen convention.

From Wikipedia :

The coordinates of the P point can change due to the rotation of the CS coordinate system (alias) or the rotation of the P point (alibi).

In most cases, the effect of ambiguity is equivalent to the effect of inverting the rotation matrix (for these orthogonal matrices, transposition of the matrix is ​​equivalent).

+1


source







All Articles