Fix create Rotation from scaled matrix

Support for creation of Rotation from matrices which is a combination of non uniform scale and a rotation
Fixes according to review
Scale -1 is Uniform, Not NoScaling
Fix hasScale() when negative scale
This commit is contained in:
Jolbas
2023-02-17 17:05:12 +01:00
committed by Chris Hennes
parent bdb6e1bd55
commit 6c3efbdb3b
3 changed files with 88 additions and 20 deletions

View File

@@ -253,6 +253,35 @@ class AlgebraTestCase(unittest.TestCase):
self.assertEqual(m2, m3*m4 , "Wrong multiplication order")
self.assertNotEqual(m2, m4*m3, "Wrong multiplication order")
def testRotationFromMatrix(self):
m1 = FreeCAD.Matrix()
m1.rotateZ(.2)
m1.scale(0.5)
m1.rotateY(.2)
m1.scale(3)
m1.move(10,5,-3)
r1 = FreeCAD.Rotation(m1)
m2 = FreeCAD.Matrix()
m2.rotateZ(.2)
m2.rotateY(.2)
m2.move(10,5,-3)
r2 = FreeCAD.Rotation(m2)
self.assertTrue(r1.isSame(r2, 1e-7), 'Scale on matrix influenced rotation')
m3 = FreeCAD.Matrix()
m3.scale(-1)
r3 = FreeCAD.Rotation(m3)
r0 = FreeCAD.Rotation()
self.assertTrue(r3.isSame(r0, 1e-7), 'Scale on matrix influenced rotation')
m4 = FreeCAD.Matrix()
m4.scale(1.25,1.0,0.25)
m4.move(4,5,6)
r24 = FreeCAD.Rotation(m2*m4)
r42 = FreeCAD.Rotation(m4*m2)
self.assertTrue(r2.isSame(r24, 1e-7), 'Scale on matrix influenced rotation')
self.assertTrue(r2.isSame(r42, 1e-7), 'Scale on matrix influenced rotation')
def testRotation(self):
r=FreeCAD.Rotation(1,0,0,0) # 180 deg around (1,0,0)
self.assertEqual(r.Axis, FreeCAD.Vector(1,0,0))
@@ -526,6 +555,11 @@ class MatrixTestCase(unittest.TestCase):
self.mat.setRow(1, FreeCAD.Vector(1,2,3))
self.mat.setRow(2, FreeCAD.Vector(1,2,3))
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Other)
self.mat.unity()
self.mat.scale(-1.)
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Uniform)
self.mat.scale(-2.)
self.assertEqual(self.mat.hasScale(), FreeCAD.ScaleType.Uniform)
def testShearing(self):
self.mat.setRow(1, FreeCAD.Vector(0,1,1))