POV-Ray : Newsgroups : povray.advanced-users : Matrix question : Re: Matrix question Server Time
5 May 2024 02:53:10 EDT (-0400)
  Re: Matrix question  
From: Josh English
Date: 22 Dec 2000 11:29:57
Message: <3A4381AC.4EADC643@spiritone.com>
Rune wrote
I have a matrix A. Then I transform it by the matrix B. The result is Matrix

> C. Given A and C, how do I find B ?
>
> Instead of matrixes the input and output should be sets of 4 vectors each.
>
> I imagine a macro like this:
>
> FindMatrix (Ax,Ay,Az,Ap,Cx,Cy,Cz,Cp)
>
> It would #declare the vectors Bx, By, Bz and Bp

Tricky question.... well, not tricky, but complicated.
You can find B as the product of A^-1*C, so finding that inverse is tricky.

For a square matrix A, the inverse of A is 1/det(A)*adj(A), or in English, the
Adjoint of A divided by the determinant. (The determinant is a scalar value that
we can find from A).

So, A =
a b c 0
d e f  0
g h i 0
j k l 1.

(I know, a fixed width font would be good for that.)
To find the determinant of A, we can use a shortcut and use the fourth column,
so we only need to find the determinant of the 3 by 3 matrix a...i:
det(A) = a(ei - fh) - b(di - fg) + c(dh - eg)  and you better make sure that
this doesn't equal 0, if it does you can't find an inverse.

To find the adjoint we find the cofactors of A which is defined by
(-1)^(i+j)det(Mij)  Here i and j refer to the row and column of the matric
element (just to clarify a muddy situation)
Mij is the Minor of Aij, which means we remove row i and column j and we have a
smaller square matrix (3 by 3 in this scenario)
So to find the Minor of a in our original matrix, we are left with the 3 by 3
matrix
e f 0
h i 0
k l 1
and since we need the determinant of this three by three matrix, we take
advantage of the last column, and det(M11) = ei - fh. I hope you understand,
because I leave you to figure out the rest of the Minors, and remember that you
still have to mulitply the determinant of the Minor by (-1)^(i + j), basically,
this forms a checkerboard pattern of negatives, so the the determinant of the
Minor calculated for element a  is normal, the determinant for the Minor
calculated for values b,d,f,h,j, and l are multiplied by -1, and you will still
have minors down the fourth column.
Once you have 16 cofactors, divide each one by the determinate we calculated in
the beginning, and you should have your inverse matrix. If you want to check,
multiply A by its inverse and see if you get the identity matrix, which is a
matrix of 0's except the diagonal from top left to bottom right should be 1's.

This is probably more glib than it needs to be, so I won't be offended by
questions.

--
Josh English -- Lexiphanic Lethomaniac
eng### [at] spiritonecom
The POV-Ray Cyclopedia http://www.spiritone.com/~english/cyclopedia/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.