Reputation: 5414
I'm using WPF's MatrixTransform for managing my translation, scaling, and rotation on a Canvas (all 2D). It works well. However, I would like to be able to calculate the current angle of rotation. How is this done? Do I need to invert the matrix and then use that to rotate something? I can provide a "rotation-at" point if necessary.
Upvotes: 1
Views: 2148
Reputation: 27495
Assumptions:
Steps:
You can ignore the final translation component, giving you the upper left 3x3 matrix that contains scale and rotation.
Scaling is just multiplication by a diagonal matrix of scaling factors (scaling each column in the matrix), so you can normalize the column vectors to give you an orthonormal matrix that purely expresses rotation.
To get an angle of rotation, you either need to choose an axis of rotation or a vector you want to rotate (from which you can compute a rotation axis and angle.)
The latter case is easier:
Upvotes: 1