#### Archived

This topic is now archived and is closed to further replies.

# Inverse of Matrix

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am 99.99% sure something is SERIOUSLY wrong with this inverse algorithm. it produces a matrix that works about 50% of cases. Could anyone look over my algorithm co i really cannot find any reason why it doesnt work 100%. Below is the Inverted() functions and all the relavant definitions
matrix4 cMatrix4::Inverted()
{
matrix4 a;
point3 p(_41,_42,_43);
float x=p*point3(_11,_12,_13);
float y=p*point3(_21,_22,_23);
float z=p*point3(_31,_32,_33);

return matrix4( _11, _21, _31, 0.f,
_12, _22, _32, 0.f,
_13, _23, _33, 0.f,
-x,  -y,  -z, 1.f);
}

float operator*(point3 const &a, point3 const &b)
{
return a.x*b.x+a.y*b.y+a.z*b.z;
}

typedef class cMatrix4
{
public:
union
{
float m[4][4];
struct
{
float _11, _12, _13, _14,
_21, _22, _23, _24,
_31, _32, _33, _34,
_41, _42, _43, _44;
};
};

cMatrix4( float n11,float n12,float n13,float n14,
float n21,float n22,float n23,float n24,
float n31,float n32,float n33,float n34,
float n41,float n42,float n43,float n44)
{
m[0][0]=n11; m[0][1]=n12; m[0][2]=n13; m[0][3]=n14;
m[1][0]=n21; m[1][1]=n22; m[1][2]=n23; m[1][3]=n24;
m[2][0]=n31; m[2][1]=n32; m[2][2]=n33; m[2][3]=n34;
m[3][0]=n41; m[3][1]=n42; m[3][2]=n43; m[3][3]=n44;
}
} matrix4;


##### Share on other sites
Hmmm.. Well, I''m not familiar with the inversion algorithm that you''re using, and I can''t see how it can work.

The only way I know of doing a matrix inverse is:

A-1 = Adj( A ) / |A|

Death of one is a tragedy, death of a million is just a statistic.

##### Share on other sites
Forgot to mention im 16 years old and dont know matrix math all that well(havent learnt it in school yet) so could you possibly offer link to an algorithm employing the formula you supplied. As far as i can understand tho the algorithm i have should only work if the matrix it inverts rcontains oly rotations and translations, which all my matrices do but still it doesnt work on half of them.

the whole matrix thing is a nightmare to say the least.. i have already reviewed half of my matrix functions (comparing them to matching functions of graphics libraries or articles in the internet) but still the thing is messed up completely.

##### Share on other sites
What do you need it for?

##### Share on other sites
Your algorithm looks really weird, and quite suspicious, since it only requires a handful of operations. Where did you take it?

Anyway, Google for "Matrix inversion" and you should find plenty of results. I think that the preferred method is Gauss'', for numerical calculations.

Cédric

##### Share on other sites
OK. Your algorithm is basically transposing the rotation part of the matrix (the upper 3*3 part), and adjusting the translation offset (the thing with the dotproduct).

That algorithm is in no way a general purpose inversion algorithm. It will only work on orthonormal rotation matrices, with an optional translation component. Any other matrix will fail (especially those involving scaling, shearing, projection, etc).

For a general inversion algorithm, read up on determinants and Kramer's rule. Here is a starting point.

[edited by - Yann L on July 5, 2003 12:39:40 PM]

##### Share on other sites
Figured that much (that it is only for rotations and transaltions.. even wrote so in my previous(second) post. Actually i only needed to invert the rotation-transaltion matrices. Also i actually took the time to read up on the determinants and although it is a little beyound me i think i got the point and could write up the algorithm. Anyways from what i can see my problem seems to be in another place. Thank you all anyways.

##### Share on other sites
I''m only 15 but I tought myself matrices, for a fully (from scratch) explanation of inversing a matrix 2x2 or 3x3 etc.., go here

http://gamedev.net/community/forums/topic.asp?topic_id=156923

##### Share on other sites
Or, well, I like plugging myself:

<plug>
Vectors and Matrices: A Primer
</plug>

It explains matrix inversions and other rudimentary stuff. It''s in the forum FAQ aswell if you looked...

Death of one is a tragedy, death of a million is just a statistic.

• 47
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631373
• Total Posts
2999643
×