How to create an inverse transformation matrix

I am working on an OpenGL project in Java, and he came to the conclusion that I would like to create transformation matrices in my own code, so I can use them to create transformations of points between screens, and vice versa. I created a transformation-enabled Matrix class, and it all works very well. However, I am having problems with how to define the inverse transform.

So my question is:

  • For an arbitrary affine (4x4) transformation matrix, how do you create an inverse transformation matrix? Are some matrices irreversible? What are the limitations and reservations about the inversion of the transformation matrix?

From my research, I have heard various ways of doing this, the simplest being to carry, and then negate the matrix. However, this does not seem to work. I heard that this method does not work on some matrices, and even if some matrices are irreversible.

I am looking for more than just the answer "plug in this equation" because I really wanted to understand what happens when I invert the matrix. It also excludes the answers โ€œjust use this libraryโ€. I can go to the matrix library in the future, but now I would like to create it myself.

Edit: Before anyone asks, this is NOT homework. This is a personal project.

Edit: there seems to be a whole list of strategies for calculating inverse matrices here: http://en.wikipedia.org/wiki/Invertible_matrix

+4
source share
1 answer

Here is some code that I used in my computer graphics course, I mainly used the Gauss Jord exception to calculate the inverse of the matrix. In order for the matrix to be reversible, its determining value must be non-zero. I did not handle this case in my code, although I am not going to do all this for you.

Matrix4* Matrix4::FindInverse(Matrix4 &a){ int n = R; int i = 0; int j = 0; float pivot = 0; Matrix4* invA = NULL; //TODO: Check whether the matrix is invertible.Else Return invA = new Matrix4(); invA->SetMatrix4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1); for(i = 0; i < n; i++){ pivot = av[i][i]; if(pivot != 1.0 and pivot != 0){ for(int t = i; t < n; t++){ av[i][t] = av[i][t]/pivot; invA->v[i][t] = invA->v[i][t]/pivot; } } //Update to the new pivot which must be 1.0 pivot = av[i][i]; for(j = 0; j < n; j++){ if( j==i ){ continue; } else{ float l = av[j][i]/pivot; for(int m = 0; m < n; m++){ av[j][m] = av[j][m] - l * av[i][m]; invA->v[j][m] = invA->v[j][m] - (l * invA->v[i][m]); } } } } return invA; 

}

+2
source

Source: https://habr.com/ru/post/1437668/


All Articles