Encoding of rotation in Transformation matrices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to decompose combos of translation and rotation matrices back into the translation vector and rotation and I found this strange thing. Can anyone can shed some light on this?
The rotation angle should be encoded in the matrix like this:
and therefor the rotation angle can be calculated with this formula:
Transform transform = Transform.CreateRotation(XYZ.Z, Math.PI/4); dobule rotation = Math.Atan2(transform.BasisY.X, transform.BasisX.X);
The weird thing is that while positive angles rotate geometry counter-clockwise in Revit, the matrix basis vectors encode it like it would be negative and therefor return a negative angle from the formula
For example the matrix that Transform generates for a 45 degrees rotation is
(0.707106781, 0.707106781, 0.000000000)
(-0.707106781, 0.707106781, 0.000000000)
(0.000000000, 0.000000000, 1.000000000)
BasisY.X should be sin(45) -> 0.707106781, but it is -0.707106781 -> sin(-45)
I know it is easy to correct it by changeing the sing of the value returned from Atan2, but why does it behave like this?
Thanks,
Taavi