Undo-Matrix Transform?

Started by
5 comments, last by CProgrammer 17 years, 11 months ago
Okay great, so you transform a vector by the matrix. I do it like this

/*For this one i copied source from my old code, not to sure if its correct*/
// Input,matrix & vector
__declspec(dllexport) void mTransform(float *m,float &x,float &y,float &z)
{
	float tvx,tvy,tvz;
	tvx = x*m[0]+y*m[4]+z*m[8]  + m[12];
	tvy = x*m[1]+y*m[5]+z*m[9]  + m[13];
	tvz = x*m[2]+y*m[6]+z*m[10] + m[14];
	x = tvx;
	y = tvy;
	z = tvz;
}

Now I wrote this down on paper, tried some algebra and realised.. Hell no, it's not happening that way, atleast not on 2 a4 sides. So according to theory if i Invert the matrix M I can just apply the same transform (backwardly). Anyone has some source code on inversing a matrix 4x4?
----------------------------

http://djoubert.co.uk
Advertisement
You can read about the properties of matrix inverses at Mathworld on "Matrix Inverse". It mentions (and links to) three ways to find the inverse a matrix near the bottom of the article.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Which method would be best, something which doesn't take to long, is fairly accurate and consistant.

Linear time would be best...
----------------------------

http://djoubert.co.uk
Search for something like 'inverse matrix' here on GDNet.

I found this.

Im not absolutely sure but from looking at your transform function there I think you might be able to optimise and get away with simply inverting the translation vector in the matrix then finding the inverse of the 3x3 rotation sub-matrix. Im sure somebody else here can confirm/deny that for you though.
Well, there's a method to invert a matrix. Call A the matrix and B it's inverse.

If you do several operations over A's lines to get the indentity matrix, you can do those same operations on the identity to get to B. The problem is you shouldn't have floats and doubles in the matrix, this way, or you will lose precision. I once created an algorithm to echelon a matrix (or however you call it in english), but it was out of my mind, not using those more efficient stuff out there.
For 4x4, using the adjoint matrix is the simplest, and the efficiency is not too bad.

http://home.earthlink.net/~w6rmk/math/matinv.htm

I use it, and I've seen many professionals use it. Don't use it for larger matrices though, as it gets expensive.
--== discman1028 ==--
Assuming you are using those matrix transformations for graphics you could always undo transform based on how the matrix was created. For instance if its a rotation matrix by 45 degrees, just use a rotation matrix by -45 degrees ...

This topic is closed to new replies.

Advertisement