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

Campbell Barton ideasman42 at gmail.com
Wed Jul 27 14:43:22 CEST 2011


I'll be sure to include this in the API docs, possibly my change to
repr caused more confusion since the string output of a matrix is:

>>> Matrix()
Matrix(((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.0, 0.0, 1.0)))


We could remove \n's

Matrix(((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.0, 0.0, 1.0)))

... for __repr__ and have a __str__ method that gives a more typical
math style print.

Either way, notes in docs explaining this would be good so we can
point devs here since its a re-occurring topic.

On Wed, Jul 27, 2011 at 8:47 PM, Benoit Bolsee <benoit.bolsee at online.be> wrote:
> Hi, I repeat once more: mathutils matrices are COLUMN-MAJOR. This means
> that the top elements in the definition list are columns, not rows,
> despite the fact that they are printed horizontaly. So the following
> code:
>
> m1 = Matrix([[ 1,  0,  2], [-1,  3,  1]])
> m2 = Matrix([[3, 1],[2, 1],[1, 0]])
> print(m1*m2)
>
> Translates into this in ordinary notation:
>
> (1 -1) X (3  2  1) = (2  1  1)
> (0  3)   (1  1  0)   (3  3  0)
> (2  1)               (7  5  2)
>
> Which is exactly what blender returns.
>
> Mathutils matrices are column-major because that's how Blender stores
> the matrices internal, and Blender uses that convention because openGL
> uses it.
>
>
>> -----Original Message-----
>> From: bf-committers-bounces at blender.org
>> [mailto:bf-committers-bounces at blender.org] On Behalf Of
>> bf-committers-request at blender.org
>> Sent: mercredi 27 juillet 2011 12:00
>> To: bf-committers at blender.org
>> Subject: Bf-committers Digest, Vol 84, Issue 26
> On Tue, 26 Jul 2011 16:49:54 +0200, "Peter K.H. Gragert"
> <pkhgragert at gmail.com> wrote:
>>
>> Hallo,
>> First try ...
>>
>> Put this text in the console and run it
>> ============code start=============
>> import bpy
>> from mathutils import Matrix
>> print("\n----START---")
>> m1 = Matrix([[ 1,  0,  2],
>>         [-1,  3,  1]])
>> print(m1, "\nelement R(2,3)")
>>
>> m2 = Matrix([[3, 1],
>>         [2, 1],
>>         [1, 0]])
>> print(m2, "\nelement R(3,2)")
>>
>> print("m1 * m2 =", m1*m2, " should be element R(2,3) * R(3,2)
>> => R(2,2) but is R(3,3) so math it looks like m2 * m1 so it
>> is STRANGE!")
>>
>> print("m2*m1 = ", m2*m1, " should be element R(3,2) * R( 2,3)
>> => R(3,3) but is R(2,2) so math it looks like m1 *
>> m2,(consistantly) STRANGE")
>>
>> # checking what *= means
>> m1_Copy = m1.copy()
>> m1_Copy *= m2
>> m1_BlStar_m2 = m1_Copy
>> print("m1 BLender *= m2",  m1_BlStar_m2 ,"should be element
>> dependant of what *= means , right or left multiplication")
>> print("result shows it is interpretated as math: m1 * m2,
>> \n\n ==> so  math RIGHT  multiplication!")
>> print( "check:",   m1 * m2 == m1_BlStar_m2 )
>> print("\n+++++++++++++ now again?!!??? ")
>> m1_BlStarm_m2_Copy = m1_BlStar_m2.copy()
>> m1_BlStarm_m2_Copy *= m2
>> m1_BlStar_m2_BlStar_m2 = m1_BlStarm_m2_Copy
>> print(" m1 BlStar_m2_BlStar_m2 =\n", m1_BlStar_m2_BlStar_m2,
>> "\nshould be ERROR R(3,3) * R(3,2) => R(3,2) but is R(3,3) ERROR!")
>>
>> ============code end=============
>>
>>
>> ==>   matrix multiplication is NOT like math matrix multiblication
>>
>> m1 * m2 in Blender correspondent with m2 * m1 in math
>> (STRANGE not nice .... but ... let it be so)
>>
>> But THEN  *=
>> m2  *=  m1 behaves very strange and to my opinion wrong!
>>
>> Greetings
>>    Peter K.H. Gragert
>>
>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>



-- 
- Campbell


More information about the Bf-committers mailing list