Base: fix conversion from Placement to Matrix

See also: https://forum.freecadweb.org/viewtopic.php?f=3&t=61000
This commit is contained in:
wmayer
2022-04-29 13:45:50 +02:00
parent f2698ac017
commit 80c900cf52
2 changed files with 26 additions and 4 deletions

View File

@@ -172,10 +172,14 @@ void Rotation::getValue(Matrix4D & matrix) const
{
// Taken from <http://de.wikipedia.org/wiki/Quaternionen>
//
const double x = this->quat[0];
const double y = this->quat[1];
const double z = this->quat[2];
const double w = this->quat[3];
const double l = sqrt(this->quat[0] * this->quat[0] +
this->quat[1] * this->quat[1] +
this->quat[2] * this->quat[2] +
this->quat[3] * this->quat[3]);
const double x = this->quat[0] / l;
const double y = this->quat[1] / l;
const double z = this->quat[2] / l;
const double w = this->quat[3] / l;
matrix[0][0] = 1.0-2.0*(y*y+z*z);
matrix[0][1] = 2.0*(x*y-z*w);

View File

@@ -407,6 +407,24 @@ class MatrixTestCase(unittest.TestCase):
res = self.mat * mat
self.assertEqual(type(res), FreeCAD.Matrix)
def testMatrixPlacementMatrix(self):
# Example taken from https://forum.freecadweb.org/viewtopic.php?f=3&t=61000
mat = FreeCAD.Matrix(-0.470847778020266,
0.8150598976807029,
0.3376088628746235,
-11.25290913640202,
-0.8822144756796808,
-0.4350066260577338,
-0.180185641360483,
-2876.45492562325,
1.955470978815492e-9,
-0.3826834326750831,
0.923879538425552,
941.3822018176414)
plm = FreeCAD.Placement(mat)
mat = plm.toMatrix()
self.assertEqual(mat.hasScale(), FreeCAD.ScaleType.NoScaling)
def testAnything(self):
with self.assertRaises(NotImplementedError):
self.mat * "string"