I've needed to try and figure this one out too so here's my two cents and
some random matrices.

Since Blender uses column major order matrices these printouts are actually
"visually transposed" to normal math, actual matrix columns are shown
horizontally in the inner brackets and rows are vertical. So the 2.5 in a*b
((a*b)[2][0] -> column 2, row 0) is a result of dot produt (a row 0,  b
column 2) as it should be -> dot( (1.0, 0.0, 1.0, 0.0), (0.5, 1.0, 2.0, 0.0)
).

>>> a
Matrix((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(1.0, 0.0, -1.0, 0.0),
(0.0, 0.0, 0.0, 1.0))

>>> b
Matrix((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(0.5, 1.0, 2.0, 0.0),
(0.0, 0.0, 0.0, 1.0))

>>> a*b
Matrix((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(2.5, 1.0, -2.0, 0.0),
(0.0, 0.0, 0.0, 1.0))

>>> b*a
Matrix((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(0.5, -1.0, -2.0, 0.0),
(0.0, 0.0, 0.0, 1.0))

One nice thing about this is that the columns are the axises (0,1,2) and
translation (3) of a matrix, so a camera direction for example would be
-a[2][0:3].

2011/7/20 Campbell Barton <[email protected]>

> On Wed, Jul 20, 2011 at 3:37 PM, Scott Giese <[email protected]>
> wrote:
> > Hi Gang,
> >
> >
> >
> > FYI. I submitted 3 patches for your review.  I'm new to the list and I
> > wanted to give back to the Blender community.
> >
> >
> >
> > 28030  SCONS Build: Build Date reflects
> > <
> http://projects.blender.org/tracker/index.php?func=detail&aid=28030&group_i
> > d=9&atid=127> "1" instead of actual date of build
> >
> > 28031  Minor typo in Blenlib
> > <
> http://projects.blender.org/tracker/index.php?func=detail&aid=28031&group_i
> > d=9&atid=127>
> >
> > 28032  Python Mathutils: Matrix Multiplication Error
> > <
> http://projects.blender.org/tracker/index.php?func=detail&aid=28032&group_i
> > d=9&atid=127>
> >
> >
> >
> > Great work guys!  Appreciate the great product.
> >
> >
> >
> > Scott
>
> Thanks for the fixes, committed all patches however you're changes to
> mathutils effectively only change the order of multiplication,
>
>
> http://projects.blender.org/tracker/index.php?func=detail&aid=28032&group_id=9&atid=127
>
> In you're example
> >>> print (m1 * m2)
>
> Change to...
> >>> print (m2 * m1)
>
> This is a bit confusing because in C we have
> mul_m4_m4m4(m1, m2);
>  which is the equivalent to "m2 * m1" in python.
>
> A while back Benoit Bolsee was concerned our matrix multiplication
> order was wrong so we switched it (between 2.4x and 2.5x)
>
> What makes you think the order in blender is wrong? what's you're
> reference?
>
> Just checked and we're currently doing matrix multiplication
> differently to numpy which doesn't bode well :S - test:
>
> # --- snip
> m1 = ((0.0, 0.0, 1.0, 0.0), (-1.0, 0.0, 0.0, 0.0), (0.0, -1.0, 0.0,
> 0.0), (0.6, 0.0, -0.05, 1.0))
> m2 = ((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0,
> 0.0), (0.0, -0.02, -0.1, 1.0))
>
> from numpy import matrix
> n_m1 = matrix(m1)
> n_m2 = matrix(m2)
> print("\nnumpy\n%r" % (n_m1 * n_m2))
>
> from mathutils import Matrix
> b_m1 = Matrix(m1)
> b_m2 = Matrix(m2)
> print("\nmathutils\n%r" % (b_m1 * b_m2))
>
> # --- output
>
> numpy
> matrix([[ 0.  ,  0.  ,  1.  ,  0.  ],
>        [-1.  ,  0.  ,  0.  ,  0.  ],
>        [ 0.  , -1.  ,  0.  ,  0.  ],
>        [ 0.6 , -0.02, -0.15,  1.  ]])
>
> mathutils
> Matrix((0.0, 0.0, 1.0, 0.0),
>       (-1.0, 0.0, 0.0, 0.0),
>       (0.0, -1.0, 0.0, 0.0),
>       (0.62, 0.1, -0.05, 1.0))
>
>
> # --- switch m1/m2 order for both mathutils and numpy. re-run
>
> numpy
> matrix([[ 0.  ,  0.  ,  1.  ,  0.  ],
>        [-1.  ,  0.  ,  0.  ,  0.  ],
>        [ 0.  , -1.  ,  0.  ,  0.  ],
>        [ 0.62,  0.1 , -0.05,  1.  ]])
>
> mathutils
> Matrix((0.0, 0.0, 1.0, 0.0),
>       (-1.0, 0.0, 0.0, 0.0),
>       (0.0, -1.0, 0.0, 0.0),
>       (0.6, -0.0, -0.15, 1.0))
> _______________________________________________
> Bf-committers mailing list
> [email protected]
> http://lists.blender.org/mailman/listinfo/bf-committers
>
_______________________________________________
Bf-committers mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-committers

Reply via email to