Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove axis from a rotation matrix?

Tags:

math

opengl

3d

I have an opengl arbitrary rotation matrix and would like to remove the X & Y axis, leaving me with only the Z axis?

Is this possible? Any pointers on how to do it?

like image 328
Paul S Avatar asked Apr 21 '11 08:04

Paul S


People also ask

How do you extract angles from a rotation matrix?

Given a rotation matrix R, we can compute the Euler angles, ψ, θ, and φ by equating each element in R with the corresponding element in the matrix product Rz(φ)Ry(θ)Rx(ψ). This results in nine equations that can be used to find the Euler angles. Starting with R31, we find R31 = − sin θ.

What is the inverse of a rotation matrix?

The inverse of a rotation matrix is its transpose, which is also a rotation matrix: The product of two rotation matrices is a rotation matrix: For n greater than 2, multiplication of n×n rotation matrices is not commutative.


1 Answers

In a rotation that is only around the z-axis, the z axis should remain unchanged. So the above recommendation is sort of the reverse of what you want.

Let's assume you have an arbitrary OpenGL matrix:

    | r_xx r_xy r_xz t_x |
    | r_yx r_yy r_yz t_y |
M = | r_zx r_zy r_zz t_z |
    |  0    0    0    1  |

Where the t_i elements are translations and the r_jk elements are components of rotation. You want a matrix that looks like this:

| cos(th) sin(th)  0  t_x |
|-sin(th) cos(th)  0  t_y |
|  0       0       1  t_z |
|  0       0       0   1  |

Unless the matrix has scaling factors or is close to a singularity, you should be able to get this by just zeroing out the z parts of the matrix and then re-normalizing the columns. Since an OpenGL matrix is column major order:

double xLen = sqrt(M[0]*M[0] + M[1]*M[1]); // Singularity if either of these
double yLen = sqrt(M[4]*M[4] + M[5]*M[5]); //  is equal to zero.

M[0]/=xLen; M[1]/=xLen; M[2]=0; // Set the x column
M[4]/=yLen; M[5]/=yLen; M[6]=0; // Set the y column
M[8]=0; M[9]=0; M[10]=1;        // Set the z column
//Don't change the translation column
like image 199
JCooper Avatar answered Sep 21 '22 16:09

JCooper