Rotation data to/from matrix

I know that this has to be around somewhere, but I must not be searching in the right places.

I need to find a way to convert - essentially, I think - rotation angles into a rotation matrix, and vice-versa.

I think I’m essentially asking about Euler angles here, but not quite sure. I also recall somewhere saying that extracting angles from the matrix is more difficult.

Note: I’m trying to accomplish a save-state for accumulated rotations, but I don’t believe that I want to store the whole matrix. Secondly, all rotations will be occurring - locally at least - along only the X and Y axises. However, as you begin to accumulate rotations, the object’s Z axis will become involved.

Please note, I am not at all interested in using quaternions for the solution to this problem. Don’t even suggest them. This must be an angle/matrix based solution.



Creating a 3x3 matrix from Euler angles is pretty simple. You do need to define the order of rotation.

Obtaining Euler angles from a 3x3 matrix is not that simple and there is more than one solution. E.g. rotate 90 deg around the X-axis and then rotate 90 deg around the Y-axis will produce the same matrix as rotating 90 deg around the Z-axis. You’ll also run into inaccuracies pretty fast if you convert Euler to Matrix back and forth.

You should probably keep your eulers and convert to a matrix when you need to:

Rx = {1 0 0}, {0 cos -sin}, {0 sin cos}
Ry = {cos 0 sin}, {0 1 0}, {-sin 0 cos}
Rz = {cos -sin 0}, {sin cos 0}, {0 0 1}
M = RzRyRx

[This message has been edited by Sinnsyk (edited 02-09-2001).]