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. -
I was just looking through the "wiki article on transformation matrices":http://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations 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":http://en.wikipedia.org/wiki/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...