From: gmt@aviator.cis.ufl.edu (Gary McTaggart)
Newsgroups: comp.graphics.algorithms
Subject: Re: Request: Inverse of a 4x4 matrix algorithm
Date: 21 May 1994 20:44:04 GMT
Mike Matsel (matsel@cs.uoregon.edu) wrote:
Does anyone have C code, or at least some psuedo-code for the finding the inverse of a 4 x 4 matrix? Its for a ray tracer. Thanks!
In a lot of cases in graphics, you will be strictly dealing with affine transforms. (My cheesy non-definition of affine is that you are only dealing with translations, rotations, and scaling. . .no shearing or perspective projection.) If this is the case, then you can use the following to find the inverse:
// (Note that a Matrix is:
// typedef float Matrix[4][4];
//
// Generally speaking, a matrix doesn't need to be bigger than 4x3, but
// since this code is to work with GL and it uses 4x4 matrices. . .
// Find the inverse of a matrix that is made up of only scales, rotations,
// and translations.
void MatrixAffineInverse( Matrix m, Matrix result )
{
float Tx, Ty, Tz;
// The rotational part of the matrix is simply the transpose of the
// original matrix.
result[0][0] = m[0][0];
result[1][0] = m[0][1];
result[2][0] = m[0][2];
// The right column vector of the matrix should always be [ 0 0 0 1 ]
// In most cases. . . you don't need this column at all because it'll
// never be used in the program, but since this code is used with GL
// and it does consider this column, it is here.
result[0][3] = result[1][3] = result[2][3] = 0;
result[3][3] = 1;
// The translation components of the original matrix.
Tx = m[3][0];
Ty = m[3][1];
Tz = m[3][2];
// Rresult = -(Tm * Rm) to get the translation part of the inverse
result[3][0] = -( m[0][0] * Tx + m[0][1] * Ty + m[0][2] * Tz );
result[3][1] = -( m[1][0] * Tx + m[1][1] * Ty + m[1][2] * Tz );
result[3][2] = -( m[2][0] * Tx + m[2][1] * Ty + m[2][2] * Tz );
}
0
Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails
Sounds like a homework assignment? I have to ask you... Do you know how to get the inverse of a matrix by hand?? If you can't do it by hand then you really won't be able to understand or even write a program to do it for you.
If you do know how to get the inverse by hand the just write code to do what you would do. I know that it won't be the best code, but it will be a good starting point.
you are right kelly it's a homework but I know how to get it by hand but this code should be able to get the inverse of a matrix bigger than a 4 X 4 and that's where I fall dowm! but I'll keep trying and see what I come up with
After years of analyzing threat actor behavior, itâ€™s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.
Preface
I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
Summary:
This tutorial covers some basics of pointer, pointer arithmetic and function pointer.
What is a pointer:
A pointer is a variable which holds an address.Â This address might be address of another variable/address of devices/address of fuâ€¦