From 642a3e509432816a4313aedb4792ac8ef79e5cdc Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 22 Oct 2012 16:21:27 +0200 Subject: [PATCH] 0000856: Wrong inverse of a matrix --- src/Base/Matrix.h | 4 +++- src/Base/MatrixPyImp.cpp | 4 ++-- src/Mod/Test/BaseTests.py | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Base/Matrix.h b/src/Base/Matrix.h index b6aa5349d..63ac6db79 100644 --- a/src/Base/Matrix.h +++ b/src/Base/Matrix.h @@ -134,9 +134,11 @@ public: /// transform (move,scale,rotate) around a point void transform (const Vector3f& rclVct, const Matrix4D& rclMtrx); void transform (const Vector3d& rclVct, const Matrix4D& rclMtrx); + /// Matrix is expected to have a 3x3 rotation matrix. void inverse (void); - /// if matrix is orthogonal a special way of getting the inverse is used + /// Matrix is expected to have a 3x3 rotation matrix. void inverseOrthogonal(void); + /// Arbitrary, non-singular matrix void inverseGauss (void); void transpose (void); //@} diff --git a/src/Base/MatrixPyImp.cpp b/src/Base/MatrixPyImp.cpp index b7d594f54..5c7eda29c 100644 --- a/src/Base/MatrixPyImp.cpp +++ b/src/Base/MatrixPyImp.cpp @@ -342,7 +342,7 @@ PyObject* MatrixPy::invert(PyObject * args) PY_TRY { if (getMatrixPtr()->determinant() > DBL_EPSILON) - getMatrixPtr()->inverse(); + getMatrixPtr()->inverseGauss(); else { PyErr_SetString(PyExc_Exception, "Cannot invert singular matrix"); return 0; @@ -361,7 +361,7 @@ PyObject* MatrixPy::inverse(PyObject * args) PY_TRY { if (getMatrixPtr()->determinant() > DBL_EPSILON) { Base::Matrix4D m = *getMatrixPtr(); - m.inverse(); + m.inverseGauss(); return new MatrixPy(m); } else { diff --git a/src/Mod/Test/BaseTests.py b/src/Mod/Test/BaseTests.py index c6442ce05..97ceb4f6a 100644 --- a/src/Mod/Test/BaseTests.py +++ b/src/Mod/Test/BaseTests.py @@ -149,6 +149,11 @@ class ParameterTestCase(unittest.TestCase): self.TestPar.RemString("44") self.failUnless(self.TestPar.GetString("44","hallo") == "hallo","Deletion error at String") + def testMatrix(self): + m=FreeCAD.Matrix(4,2,1,0,1,1,1,0,0,0,1,0,0,0,0,1) + u=m.multiply(m.inverse()) + self.failUnless(u==FreeCAD.Matrix(),"Invalid inverse of matrix") + def testNesting(self): # Parameter testing #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")