Since the Eigen3 library is shipped with Blender it would be nice to be able to access the linear algebra functions from python.
There are probaly several developers who need to use external libraries (numpy, ...) to solve certain problems. In my mesh alignment (pointcloud alignment) tool it is needed to calculate a least-squares solution for the transformation matrix.
This patch adds a new module to mathutils (mathutils.eigen) and provides a generic solve function that can solve Ax=b for x currently with * ColPivHouseholderQr * FullPivHouseholderQr * JacobiSvd
The matrices are lists of python lists [[1,0,0],[0,1,0],[0,0,1]] and vectors are either [[1],[2],[3]] or [1,2,3]. This is because the mathutils.Matrix class does not support matrices of arbitrary size.
The solver throws exceptions if the Matrix rows don't have the same size or if the rows of A and b are not equal or if the elements are not PyLong or PyFloat.
The return value is a list of values which corresponds to the vector 'x'
Attached is a little example that shows how the solver is used (solver_example.txt)
The patch can be applied with
patch -p0 -d source/blender/python < mathutils_eigen.diff
in the root of the blender directory |