[Bf-committers] matrix multiplication in Blender SVN of this morning (W32 Vista mingw compiled)

Peter K.H. Gragert pkhgragert at gmail.com
Wed Jul 27 18:06:08 CEST 2011


I  just played with numpy   and the numpy matrix behaves in print and
operation as is (for me at least)
 normally done in mathematics and so is done in the wikipedia.org about
matrices!!!

So eventually one could look there how it is done, that layout and
mathematical interpretation
is the same ... the internal ordering of matrix elemens is more or less
irrelevant.

Starting point too are vectors and an n-dimensional vector is an object with
ordered n numbers, and one says (makes!)  an element of a linear space R(n).
In combination with matrices rather often vectors are viewed as matrices
with either one row or one column  R(n,1) or R(1, n)   whereas matrices with
n rows and m columns are elements of
R(n,m).

Then matrix multiplication between those matrix spaces are only possible
with
m1 element R(n,m) and  m2 R(p,q)   ==>  m1 * m2 if and only if  m = p with
result an element of R(n,q)

now take a normal world_matrix of Blender which is an element of R(4,4),
e.g. mat.

Multiplication with a vector one has to defined  by thinking a vector as
being a matrix!
And that is very often done.
But you than have a choice: a vector  vec , element R(n),  look at it as
element of R(n,1) (column vector) or element  of R(1,n) row vector!

At THIS moment Vectors are printed in the console as row, so it would, my
opinion, be wise to say vectors in Blender are elemens of R(1,n)
(row-vectors!) with as consequence that
the multiplication of (world!!!) matrix with a vector  has to be
vec * mat, delivering again an element of R(1,n)
Meaning: mat * vec is FORBIDDEN!
Probably this is suitable too to the internal column first ordering of
matrices (but not essential)
as far as mathematically good results occur in operation but too in layout!

Now the print at THIS moment of the a (world) matrix in the Python console
as well defining a matrix is
row-wise (am I right?, I think so because
>From an 2 x 3 numpy matrix m1
>>> m1
matrix([[1, 2, 3],
        [4, 5, 6]])

Now Mathutils:
>>> M1 = Matrix(((m1[0,0],m1[0,1],m1[0,2]),(m1[1,0],m1[1,1],m1[1,2])))
>>> M1
Matrix(((1.0, 2.0, 3.0),
        (4.0, 5.0, 6.0)))
Same layout should mean same mathematical interpretation....

Result: the Blender a week ago or so was correct, not allowing Matrix *
Vector but only
Vector * Matrix.

How matrices and or vectors are stored is not so important, maybe the
execution time
prefers column first?

Greets
       Peter ( a retired mathematician ;-) )


More information about the Bf-committers mailing list