Please nominate your Qt Champions for 2021!

How to get the rotate angle by QMatrix.

  • hi,everyone!
    now I have a QMatrix, maybe it has been moved, scaled, sheared,and rotated. and I have found that scaling x and y by different factors can change the angle, but it doesn't go rotate command, so I can't record this angle. now how I can get the degree by this QMatrix, Because I want to let my graphic to be horizontal as the original.

  • Neither QMatrix nor QTransform gives you the value of the rotation. You should however be able to calculate the rotation from the mxy() (i.e. m11, m23()) values. Can't tell you how you should do that though.

  • ok,thanks Franzk。 who can tell me how to calculate the rotation from mxy()(i.e. m11, m23()) .

  • I was just looking through the "wiki article on transformation matrices": and it seems to me that you could use the following information:
    @transform.m11() == cos(theta)
    transform.m12() == -sin(theta)
    transform.m21() == sin(theta)
    transform.m22() == -cos(theta)@

    That would mean that
    @qreal theta = acos(transform.m11());@

    This all is assuming you are using QTransform (QMatrix is deprecated).

    Note that the math.h trigonometric function work with "radians": rather than degrees.

  • But, the real problem is probably the order of transformations you are doing because that can alter the result completely.. I say this because you should be able to write your transforms to get the intended result (mathematically).. without needing to try and hard-modify the matrix like you plan to.. maybe you need more specific transformation than a matrix can provide...

Log in to reply