[Bf-committers] Change Representation and Initialisation of Matrices to Conform with Standard Notation
trumanblending at gmail.com
Fri Dec 9 13:50:21 CET 2011
So it currently prints columns as rows? This is how users become confused.
This can be fixed as I propose or by changing the repr function. Changing
the repr function will at least make the printed form of the matrix
consistent with it's behaviour in multiplications, if we change the repr
then the column will be indexed first. This is fine but that would need to
be documented very well because this is not ordinarily the case in math as
you point out. Although more involved, the patch I proposed fixes the repr
issue, while allowing the user to index matices in Python by the
On Fri, Dec 9, 2011 at 11:28 PM, Brecht Van Lommel <
brechtvanlommel at pandora.be> wrote:
> 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.
> On Fri, Dec 9, 2011 at 12:37 PM, Andrew Hale <trumanblending at gmail.com>
> > 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 ,  and .
> > 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
> >  and ) the result is incorrect. Also see the patch tracker entry
> > 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.
> > is the matrix transpose, i.e. rows/columns switched.
> > Thanks,
> > Andrew
> >  http://mathworld.wolfram.com/Matrix.html
> >  http://www.mathworks.com.au/help/techdoc/math/f1-85462.html#f1-85488
> > 
> >  http://mathworld.wolfram.com/MatrixMultiplication.html
> > 
> > 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:
> >> >
> >> > 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
> Bf-committers mailing list
> Bf-committers at blender.org
More information about the Bf-committers