[Bf-committers] Change Representation and Initialisation of Matrices to Conform with Standard Notation

Brecht Van Lommel brechtvanlommel at pandora.be
Fri Dec 9 13:28:26 CET 2011


Hi Andrew,

I don't think this is the right interpretation, I think column major
storage does explain the behavior, and it's not clear to me what is
wrong assuming that this is the case.

In python and blender C code, matrices are accessed as
matrix[column][row]. When printing the matrix in python, it will print
a list of columns. A python __repr__ implementation for Matrix could
make this print better.

Brecht.

On Fri, Dec 9, 2011 at 12:37 PM, Andrew Hale <trumanblending at gmail.com> wrote:
> Hi Ton,
>
> I will try to explain better (this is a devilish topic). The problem here
> is how matrices are accessed in Python and how the matrix product is
> formed. The method of indexing matrices is shown in [1], [2] and [3]. This
> method has the method of accessing matrices as
> matrix[row_index][column_index], this is the method used in Python
> currently. However, when the product of a matrix and vector is formed
> according to normal matrix rules for a matrix times a column vector (see
> [4] and [5]) the result is incorrect. Also see the patch tracker entry for
> an example of how the matrix multiplication in Python is incorrect.
>
> The reason that the multiplication is not being calculated correctly is
> that the way matrices are printed an how they are stored is different.
> Because of this in Python when we access matrix[i][j] element, we're
> accessing element matrix[j][i] in C. Hence the product matrix*vector is
> actually computed as matrix^T * vector of what is shown on screen. matrix^T
> is the matrix transpose, i.e. rows/columns switched.
>
> Thanks,
> Andrew
>
> [1] http://mathworld.wolfram.com/Matrix.html
> [2] http://www.mathworks.com.au/help/techdoc/math/f1-85462.html#f1-85488
> [3]
> http://en.wikipedia.org/wiki/Index_notation#Index_notation_in_mathematics
> [4] http://mathworld.wolfram.com/MatrixMultiplication.html
> [5] http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_multiplication
>
> On Fri, Dec 9, 2011 at 9:01 PM, Ton Roosendaal <ton at blender.org> wrote:
>
>> Hi Andrew,
>>
>> Can you provide evidence for who is spreading, supporting or enforcing
>> this "Standard Notation"?
>>
>> Apart from that - especially when this standard appears disputable -
>> we can much better ensure we are 100% clear about it in docs. Look at
>> this wonderful Panda3d page:
>>
>> http://www.panda3d.org/manual/index.php/Matrix_Representation
>>
>> I rather see this approach for us!
>>
>> -Ton-
>>
>> ------------------------------------------------------------------------
>> Ton Roosendaal  Blender Foundation   ton at blender.org    www.blender.org
>> Blender Institute   Entrepotdok 57A  1018AD Amsterdam   The Netherlands
>>
>> On 8 Dec, 2011, at 7:05, Andrew Hale wrote:
>>
>> > Hi All,
>> >
>> > I have written a patch which rectifies a cause of confusion among
>> > Blender
>> > uses when starting out with matrices and vectors. The patch ensures
>> > consistency between the matrix representation and matrix/vector
>> > products so
>> > that they behave in the way that people familiar with math expect.
>> > This is
>> > achieved by adjusting pythons access to the internal storage, while
>> > keeping
>> > the internal data the same. Note that this does not interfere with how
>> > matrices are stored internally or how matrix products, additions etc
>> > are
>> > performed internally.
>> >
>> > The patch can be found here:
>> >
>> http://projects.blender.org/tracker/index.php?func=detail&aid=29534&group_id=9&atid=127along
>> > with a more in depth explanation.
>> >
>> > Thanks,
>> > Andrew
>> > _______________________________________________
>> > Bf-committers mailing list
>> > Bf-committers at blender.org
>> > http://lists.blender.org/mailman/listinfo/bf-committers
>>
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers


More information about the Bf-committers mailing list