Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMatrix4x4 rotate
Forum Updated to NodeBB v4.3 + New Features

QMatrix4x4 rotate

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 3.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by beecksche
    #1

    Hi,

    i want to use the rotate function from the QMatrix4x4 class. But i don't get the right QVector3D:

    QMatrix4x4 rot;
    rot.setToIdentity();
    rot.rotate(45, QVector3D(0, 0, 1)); // create rotation matrix with 45° and rotation vector in positive z-direction
    
    QVector3D test = QVector3D(1, 0, 0) * rot; //calculate the rotated vector 
    qDebug() << test; // QVector3D(0.70710678118, -0.70710678118, 0)
    

    The calculated vector should be QVector(0.70710678118, +0.70710678118, 0). Like here: http://www.nh.cas.cz/people/lazar/celler/online_tools.php?start_vec=1,0,0&rot_ax=0,0,1&rot_ang=45

    Is this a bug or do i forget something?

    1 Reply Last reply
    0
    • BjornWB Offline
      BjornWB Offline
      BjornW
      wrote on last edited by
      #2

      I'm not very familiar with this class, but usually the matrix is multiplied to the leftof the vector. (Mv is not the same as vM)

      Try:

      QVector3D test = rot * QVector3D(1, 0, 0); //calculate the rotated vector 
      
      beeckscheB 1 Reply Last reply
      4
      • BjornWB BjornW

        I'm not very familiar with this class, but usually the matrix is multiplied to the leftof the vector. (Mv is not the same as vM)

        Try:

        QVector3D test = rot * QVector3D(1, 0, 0); //calculate the rotated vector 
        
        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @BjornW

        Oh thanks! Yeah that was my fault!

        1 Reply Last reply
        2
        • BjornWB Offline
          BjornWB Offline
          BjornW
          wrote on last edited by
          #4

          You should mark this as solved :-)

          1 Reply Last reply
          1
          • kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            Just for completeness, you can multiply the vector from the right side too, but you have to transpose the matrix (it's a unitary one) beforehand to obtain a correct result. And as a general side note, I'd advise just to use QTransform instead.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            1
            • BjornWB Offline
              BjornWB Offline
              BjornW
              wrote on last edited by
              #6

              Good comment.

              Further clarification; the inverse of a rotational matrix is always its transposition. This is useful :-)

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved