def test_multiplication(self): """ Multiplying one L{Quaternion} by another returns a new L{Quaternion} giving the product of the two. """ a = Quaternion.fromAxisAngle(Vector3(1, 0, 0), pi / 4) b = Quaternion.fromAxisAngle(Vector3(1, 0, 0), pi / 6) c = a * b axis = c.getAxis() angle = c.getAngle() self.assertEqual(axis.x, 1) self.assertEqual(axis.y, 0) self.assertEqual(axis.z, 0) self.assertAlmostEqual(angle, pi / 4 + pi / 6, 6)
def test_fromAxisAngle(self): """ A L{Quaternion} can be constructed from a Vector3 giving an axis and a scalar giving an angle from that axis. """ quat = Quaternion.fromAxisAngle(Vector3(0, 1, 0), 45) self.assertTrue(isinstance(quat, Quaternion))
def test_rotation(self): transform = Transform() transform.setRotation(Quaternion.fromScalars(1, 2, 3, 4)) quat = transform.getRotation() self.assertTrue(isinstance(quat, Quaternion)) self.assertEquals(quat.getX(), 0.18257419764995575) self.assertEquals(quat.getY(), 0.3651483952999115) self.assertEquals(quat.getZ(), 0.54772257804870605) self.assertEquals(quat.getW(), 0.73029673099517822)
def test_getAxisAndAngle(self): """ A L{Quaternion} represents a rotation around an axis. L{Quaternion.getAngle} returns the rotation in radians, L{Quaternion.getAxis} returns the axis as a L{Vector3}. """ quat = Quaternion.fromScalars(0, 0, 0, 1) axis = quat.getAxis() self.assertEqual(axis.x, 1) self.assertEqual(axis.y, 0) self.assertEqual(axis.z, 0) self.assertEqual(quat.getAngle(), 0) quat = Quaternion.fromScalars(0, 0, 1, 0) axis = quat.getAxis() self.assertEqual(axis.x, 0) self.assertEqual(axis.y, 0) self.assertEqual(axis.z, 1) self.assertAlmostEqual(quat.getAngle(), pi, 6)
def test_fromScalars(self): """ A L{Quaternion} can be constructed from four scalar values giving x, y, z, and w. """ quat = Quaternion.fromScalars(1, 2, 3, 4) self.assertTrue(isinstance(quat, Quaternion)) self.assertEquals(quat.getX(), 1) self.assertEquals(quat.getY(), 2) self.assertEquals(quat.getZ(), 3) self.assertEquals(quat.getW(), 4)
def test_unrelatedMultiplication(self): """ Multiplying a L{Quaternion} but another type results in a L{TypeError}. """ self.assertRaises(TypeError, mul, Quaternion.fromScalars(0, 0, 0, 1), "foo")
def test_unrelatedMultiplication(self): """ Multiplying a L{Quaternion} but another type results in a L{TypeError}. """ self.assertRaises( TypeError, mul, Quaternion.fromScalars(0, 0, 0, 1), "foo")