# Inverse matrices and orientation

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

## Recommended Posts

Two quick questions: 1) I'm implementing a matrix library and need an inverse function to find inverse cam/world matrices etc. Is Kramer's rule the way to go? If not, can I get a recommendation. 2) Just curious as to how you guys store your game object's orientation. Euler angles, rotation matrices, quats, etc. I'm leaning towards a matrix, so that I can apply world rotations easily w/o converting from/to euler angles.

##### Share on other sites
Quote:
 Original post by Unfadable1) I'm implementing a matrix library and need an inverse function to find inverse cam/world matrices etc. Is Kramer's rule the way to go? If not, can I get a recommendation.

The inverse of an orthonormal matrix is actually just the transpose. So for a 3x3 rotation matrix you can just take the transpose. If you're using a 4x4 homogeneous transformation matrix, then you can invert it in pieces - use RT on the rotational 3x3 submatrix 'R', and use -RTd to invert the 3x1 translation submatrix 'd'.

Quote:
 Original post by Unfadable2) Just curious as to how you guys store your game object's orientation. Euler angles, rotation matrices, quats, etc. I'm leaning towards a matrix, so that I can apply world rotations easily w/o converting from/to euler angles.

Most of the time you can get away with Euler angles, but if you experience Gimbal lock problems then you'll have to switch to quaternions. Personally I've always stored Euler angles and created/updated a set of transformation matrices that I pass to DirectX/OpenGL.

##### Share on other sites
Yeah, unfortunately my matrices aren't guaranteed to be orthonormal, so I need a general solution. Kramer's rule then?

##### Share on other sites
For small matrices (4x4 and smaller), you can get away with an explicit formula (like those shown here). For a general NxN matrix, I would use Gauss-Jordan elimination.

Just out of curiosity, which matrices do you expect to be non-orthonormal, besides maybe the perspective matrix?

##### Share on other sites
Cool I'll check that out. Thanks.

The world matrix of some of my objects may have a scale applied to them.

Which reminds me of another question. Is it valid to normalize the basis vectors in a matrix and it still maintain the proper orientation? It seems like it should be, but I've never been sure.

##### Share on other sites
I completely forgot about scaling (I don't use it much). There are also tricks for inverting that transformation. You can compute the length of each basis, divide it out (so normalize the basis vectors), do the transpose thing, and divide out the length again from each of the new basis vectors. In other words, the basis vectors in R and R-1 will have inverse lengths.

This also answers your new question, that you can change the length of the basis vectors and still maintain the same orientation.

##### Share on other sites
You could perhaps include a method for for quick inverse for cases when you KNOW that the matric is orthonormal?

##### Share on other sites
Quote:
 You could perhaps include a method for for quick inverse for cases when you KNOW that the matric is orthonormal?

Oh absolutely. Depending on the scene, this operation may come up a lot and I'd definitely perfer using the transponse.

Zipster, cool trick you've posted. Much appreciated.

1. 1
2. 2
3. 3
Rutin
24
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002233
×