Important: Please read the Qt Code of Conduct -

QMatrix, QQuaternion Confusion

  • Hello,

    for the communication with another program I need to convert a Transformmatrix into a QQuaternion and back. This worked so far. (Maybe because both convertion ways where wrong so it compensated the mistake. )

    But since I added another conversion for special cases which only reads the EulerAngles of the quat, the sened X-Rotation can turn out as Z-Rotation on the other side so there must be something wrong with the order of the values in the ctors.

    The docu is not telling much so hopefully someone can see the mistake:

    Convert MyMatrix to QMatrix:

    float values[] = { uVec.x, uVec.y, uVec.z,
    				vVec.x, vVec.y, vVec.z,
    				wVec.x, wVec.y, wVec.z  };
      QMatrix3x3 rotatioMa (values); 

    Convert QMatrix to MyMatrix:

    // Column-major order

    uVec ([0],[3],[6]); // x y z
    vVec ([1],[4],[7]); // x y z
    wVec ([2],[5],[8]); // x y z

    Converting euler angles to a Quaternion:

    QQuaternion::fromEulerAngles( yRot_Pitch, zRot_Yaw, xRot_Roll); // I looked in wikipedia which axis are used for pitch, yaw and roll


  • Lifetime Qt Champion


    You should use the copyDataTo method store the matrix values and use the constructor which takes a pointer to reload them.

  • @SGaist

    Thanks for your answer.
    I guess you think I copy one QMatrix to another but the original Matrix has a different type.

    Meanwhile I totally replaced the QMatrix by the QQuaternion but still the XAngle turns out as Z at the other side. Pretty sure the problem is the order of the euler angles in the QuatCtor.

    This is the declaration:

    QQuaternion.fromEulerAngles(float pitch, float yaw, float roll);

    As mentioned I used the angles in the following order:

    fromEulerAngles(yRot, zRot, xRot);

  • Lifetime Qt Champion

    So you go from QMatrix3x3 to your own matrix and then QQuaternion through fromEulerAngles ?
    What if you use fromRotationMatrix ?

Log in to reply