Advertisement

Matrix reversing

Started by March 21, 2003 03:18 PM
5 comments, last by Amma 21 years, 10 months ago
I''m trying to implement bone animation in my engine. I''m using my own 3DS Max exporter. However, I''m reciving the matrices (4x4 - which includes the position) already transformed by the parents. So if I''m having a matrix that''ve been transformed by another matrix, how do I get the original matrix back to before it was multiplied? (I have the ''transformer''´s matrix). I''ve thought of several solutions, but I just can''t get it right. Every reply is appriciated. Thanks, Amma
-----------------------------Amma
if you are given R and M and want to find W. such that

W*M = R

W*M*inverse(M) = R*inverse(M)
W*I = R*inverse(M) (since M*inverse(M) = I)
W = R*inverse(M)

where I is the identity

of couse this is given that you know M, if you dont then, you can decompose some things from R (such as scale, rotation, translation) but you wont beable to find out the excat chain of matrix multiplications since multiplying matricies is kind of like baking a cake (you put in unique ingrediants, but once it''s been mixed there''s no way of finding the exact order and and values of initial ingrediants)
Advertisement
A*B=C; A^(-1)*A*B=A^(-1)*C; I*B=A^(-1)*C; B=A^(-1)*C where ^(-1) means the inverse of the matrix and I is the identity matrix. The easiest way to explain the inverse is a sequence of transforms than converts the original matrix to the identity matrix. The operations are to multiply a row by a constant and add a multiple of one row to another. Whether you do a row or column operation depends upon whether you multiply on the left or right. Rows is E*A where E is a matrix implementing a basic row operation. Columns is A*E. You then have a sequence EN*...*E3*E2*E1*A=I. The product (EN*...*E3*E2*E1) is the inverse matrix. Assuming row operations the matrix [[2 0 0];[0 1 0];[0 0 1]] multiplies the first row by 2 and leaves the rest unchanged. The matrix [[1 0 0];[-2 1 0];[0 0 1]] subtracts two times the first row from the second. So first you make the top left value one by multiplying the row then all the rest of the values in the first column zero by subtracting a multiple of the first row from them the other rows. You continue until everything below the diagonal is zero. So now if you subtract a multiple of a row from a row above it you have no effect on anything to the left. That is row echelon form. If you continue and make everything above the diagonal zero as well then that is reduced row echelon form. With a square matrix that is the identity matrix.

Since your goal is the inverse matrix rather than just a solution the best approach is to keep modifying the matrix you are multiplying by. You examine A and come up with E1. You then examine E1*A to come up with E2 and calculate E=E2*E1. You then examine E*A to come up with E3 and calculate E=E3*E. Continue that and at the end E is the inverse. The order of operations and whether you do rows or columns doesn't matter for the result. It does affect the individual EN's, but there is either one or no inverse to a matrix. So no matter how you do it you end up with the same matrix even though the individual steps may vary. If there is no inverse then one of the elements on the diagonal ends up with a zero. A linear transform matrix is alway invertible. A projection matrix is not. You lose data in a projection. Given a top down view of an object it is hard to tell how tall it is.

[edited by - LilBudyWizer on March 21, 2003 5:04:41 PM]
Keys to success: Ability, ambition and opportunity.
Thanks to both of you. It all makes sense.
-----------------------------Amma
Everything works, rotation wise. However, how about the position?

And when you guys say ''inverse'', you mean transpose, right?



-aMMa
-----------------------------Amma
I''m not really sure if you can make a fully-featured 4x4 inverse matrix (that is, a 3x3 matrix with translation vector included), since the inverse matrix must calculate the rotation and translation in reverse order.
(I.E, if your matrix first rotates the point and then translate it. In order to get back to your previous position, you must first translate back and then rotate it.)


quote:

And when you guys say ''inverse'', you mean transpose, right?



No. Not generally. Only matricies with pure rotational outcome has whis capability.

Electron

"The truth can be changed simply by the way you accept it."


--Electron"The truth can be changed simply by the way you accept it.""'General failure trying to read from file' - who is General Failure, and why is he reading my file??"
Advertisement
Imagine R is the 4X4 rotation matrix and T is the 4X4 translation. The combined transform (order is immaterial for the example but does of course matter):

M = R * T

R-1 * M = R-1 * R * T

R-1 * M = T

T-1 * R-1 * M = T-1 * T

T-1 * R-1 * M * M-1 = M-1

T-1 * R-1 = M-1

So the inverse does swap the order of the individual transforms.


[edited by - JuNC on March 24, 2003 8:49:45 AM]

This topic is closed to new replies.

Advertisement