View Full Version : Angle extraction from matrix
11-25-2003, 07:09 AM
I am trying to extract the angles of rotation about the x y z axes from the currnet matrix.
I use glGetDoublev to get the matrix and then the following equations
rotation y = -asin(matrix)
rotation x = atan2(matrix,matrix)
rotation z = atan2(matrix,matrix)
this works +-180 degrees for x and z rotation
but only +-90 degres for y rotation. I need +- 180 degrees for y rotation.
Hopefully someone has a simple fix.
11-25-2003, 11:07 AM
Your problem is not well constrained as stated. If you allow 180 degrees around one axes, and then 180 degrees around another axis, then there are (at least) 2 solutions that will end up in the same point.
If you want an in-depth understanding of the math involved, I suggest googling for "polar matrix decomposition."
11-25-2003, 03:02 PM
If I am not mistaken this problem is connected to the everpresent Gimbal lock. You should
search the web on Gimbal lock, Quaternion. Modify your camera code, and then the values you obtain, along with your camera controls will work without problems.
11-26-2003, 12:18 AM
Thanks for your suggestion. I am looking thru the links but so far they seem to reduce to the equations I already have.
The following restates the problem in case I have not explained myself.
Apart from special cases when the rotation about y is 90 degrees or -90 degrees the equations I have been using give 2 results; the angle and pi - angle. It is this ambiguity I would like to solve.
To demonstrate the problem render a cube using a matrix that has had 135 degree rotation applied to each axis. Decompose the matrix and you get x rotation of 135 deg
z rotation of 135 degrees and two possible results for x of 45 and 135 degrees.
11-26-2003, 05:38 AM
Just FYI: The book "Graphics Gems II" has a chapter on decomposing transformations matrices into rotation/scale/translation matrices. Perhaps that would help.
I believe the source code from all the Gems books is freely available on the net.
11-26-2003, 05:51 AM
The section in Graphic Gems II is 'Decomposing a Matrix Into Simple Transformations'. I found the source code sample on http://www.acm.org/tog/GraphicsGems
I will try the example code and see if I can understand the math.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.