Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I extract the angle of rotation from a QTransform?

I have a QTransform object and would like to know the angle in degrees that the object is rotated by, however there is no clear example of how to do this:

http://doc.trolltech.com/4.4/qtransform.html#basic-matrix-operations

Setting it is easy, getting it back out again is hard.

like image 783
Phil Hannent Avatar asked May 21 '09 14:05

Phil Hannent


1 Answers

Assuming, that the transform ONLY contains a rotation it's easy: Just take the acos of the m11 element.

It still works if the transform contains a translation, but if it contains shearing or scaling you're out of luck. These can be reconstructed by decomposing the matrix into a shear, scale and rotate matrix, but the results you get aren't most likely what you're looking for.

like image 139
Nils Pipenbrinck Avatar answered Oct 27 '22 00:10

Nils Pipenbrinck