Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Accurate Matrix Inverse

  1. #1
    Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Cambridge, England
    Posts
    270

    Accurate Matrix Inverse

    If you have some accurate (and reliable) non-affine matrix inverse code, could you post it here?
    I'm currently using the gaussian reduction method, which is mostly OK if you use double precision floats, but tends to introduce some significant inaccuracies.
    Thanks.

  2. #2
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Accurate Matrix Inverse

    I assume you've tried this one: http://www.cs.ualberta.ca/~andreas/m...atest.html#Q24

    Non-affine? Does that mean non-orthagonal?
    Knackered

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2001
    Posts
    26

    Re: Accurate Matrix Inverse

    i don't know how your matrix is and this fact should be mentionned :
    - if the matrix is not very big, you can write the real inverse using det...
    But if you needn't the inverse but only a solution of A.X=B and if your matrix is "symetric" (and better definied >=0) then use the fast gradient algorythm (or sh... my english is to bad, see http://www.univ-lille1.fr/eudil/jbeu.../gradconj.html
    )
    else the reduction used (gauss, LR, Schmidt....) depends on the form of the matrix and what you want to do with this one. Hope this helps a little.

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Cambridge, England
    Posts
    270

    Re: Accurate Matrix Inverse

    Thanks.
    An affine matrix only translates, scales and rotates. A non-affine matrix can also skew.

  5. #5
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Accurate Matrix Inverse

    You mean preserves angles. I thought scale was not including since an affine transform also suppose to preserve dimensions.

    Bad memory!

    I have been using the inverse funcion present in the GLU source code. Does anyone know what method it uses?

    V-man
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Cambridge, England
    Posts
    270

    Re: Accurate Matrix Inverse

    My understanding of the meaning of affine comes from http://www.cs.unc.edu/~gotz/code/affinverse.html so it's quite possibly wrong.

    Hmm... (search, search, search) the GLU source appears to use the Gaussian reduction method.

    Having now tried almost every bit of source code I've found to perform the inversion, I have concluded that they are all approximately equal when it comes to accuracy, and the Gaussian method is fastest.

    It seems that the inaccuracy is introduced somewhere else in my code. Back to debugging...

  7. #7

    Re: Accurate Matrix Inverse

    For small nonsingular matrices the fastest way and most accurate is the method with the least floating point operations. For a 4x4, direct solution, via Cramer's rule or some other method, is the fastest. If the matrix is symmetric only the diagonal and either the above or below diagonal terms need to be calculated. Nearly singular matrices require special and computationally expensive matrix solvers such as the HouseHolder algorithm. Generally using double precision is the first resort because it easy, computationally cheap and maybe be required anyway. If you have a nearly singular rotation or translation matrix, it is most likely you have a mistake or can scale the model to remove the problem. If you really, really need a special solver, send me an e-mail.

  8. #8
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Accurate Matrix Inverse

    Here's a more trustworthy definition :
    http://mathworld.wolfram.com/AffineTransformation.html
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    California
    Posts
    550

    Re: Accurate Matrix Inverse

    Is this the gaussian method?

    Code :
    inline void s3dMatrixInvert16f(S3Dfloat* m)
    {
    	S3Dmat16f temp;
     
    	temp[0]=m[0];
    	temp[1]=m[4];
    	temp[2]=m[8];
    	temp[3]=0.0f;
     
    	temp[4]=m[1];
    	temp[5]=m[5];
    	temp[6]=m[9];
    	temp[7]=0.0f;
     
    	temp[8]=m[2];
    	temp[9]=m[6];
    	temp[10]=m[10];
    	temp[11]=0.0f;
     
    	temp[12]=-(m[12]*m[0])-(m[13]*m[1])-(m[14]*m[2]);
    	temp[13]=-(m[12]*m[4])-(m[13]*m[5])-(m[14]*m[6]);
    	temp[14]=-(m[12]*m[8])-(m[13]*m[9])-(m[14]*m[10]);
    	temp[15]=1.0f;
     
    	memcpy(m, temp, sizeof(S3Dfloat)*16);
    }
    I believe I got this method from NitroGLs bumpmapping code.

  10. #10
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    247

    Re: Accurate Matrix Inverse

    No, WhatEver, that is not the Gaussian algorithm.

    Don't Disturb, are you using row pivoting? If you are inverting 4x4 matrices with Gaussian elimination with row pivoting (the most common method) then you should not be getting bad roundoff errors even with single precision floats. Unless your matrices are nearly singular (or poorly scaled or very large), there is probably a bug in your code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •