def test_create_from_z_rotation(self): # 180 degree turn around Z axis q = quaternion.create_from_z_rotation(np.pi) self.assertTrue(np.allclose(q, [0., 0., 1., 0.])) # 90 degree rotation around Z axis q = quaternion.create_from_z_rotation(np.pi / 2.) self.assertTrue(np.allclose(q, [0., 0., np.sqrt(0.5), np.sqrt(0.5)])) # -90 degree rotation around Z axis q = quaternion.create_from_z_rotation(-np.pi / 2.)
def test_apply_to_vector_z(self): # 180 degree turn around Z axis q = quaternion.create_from_z_rotation(np.pi) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [1., 0., 0.]), [-1., 0., 0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [0., 1., 0.]), [0.,-1., 0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [0., 0., 1.]), [0., 0., 1.])) # 90 degree rotation around Z axis q = quaternion.create_from_z_rotation(np.pi / 2.) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [1., 0., 0.]), [0., 1., 0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [0., 1., 0.]), [-1., 0., 0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [0., 0., 1.]), [0., 0., 1.])) # -90 degree rotation around Z axis q = quaternion.create_from_z_rotation(-np.pi / 2.) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [1., 0., 0.]), [0.,-1., 0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [0., 1., 0.]), [1., 0., 0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(q, [0., 0., 1.]), [0., 0., 1.]))
def rotated_z(): quat = quaternion.create_from_z_rotation( math.pi ) result = matrix33.create_from_quaternion( quat ) expected = matrix33.create_from_z_rotation( math.pi ) self.assertTrue( numpy.allclose( result, expected ), "Matrix33 from quaternion incorrect with PI rotation about Z" )
def test_apply_to_vector_z(self): quat = quaternion.create_from_z_rotation(np.pi / 2.) self.assertTrue( np.allclose(quaternion.apply_to_vector(quat, [1., 0., 0.]), [0., -1., 0.])) self.assertTrue( np.allclose(quaternion.apply_to_vector(quat, [0., 1., 0.]), [1., 0., 0.])) self.assertTrue( np.allclose(quaternion.apply_to_vector(quat, [0., 0., 1.]), [0., 0., 1.]))
def rotate_z(self, radians): """Roll the transform about it's Z axis. .. note:: Amount > 0 == roll left. Amount < 0 == roll right. """ if radians == 0.0: return quat = quaternion.create_from_z_rotation(radians) self.rotate_quaternion(quat)
def rotate_z( self, radians ): """Roll the transform about it's Z axis. .. note:: Amount > 0 == roll left. Amount < 0 == roll right. """ if radians == 0.0: return quat = quaternion.create_from_z_rotation( radians ) self.rotate_quaternion( quat )
def rotateAboutOrigin(self, xyz, t, p): rp = p - math.pi / 2 rt = -t q1 = quaternion.create_from_z_rotation(rp) q2 = quaternion.create_from_x_rotation(rt) v = vector3.create(xyz[0], xyz[1], xyz[2]) v = quaternion.apply_to_vector(q1, v) v = quaternion.apply_to_vector(q2, v) return v
def test_create_from_quaternion_rotated_z(self): quat = quaternion.create_from_z_rotation(np.pi) result = matrix33.create_from_quaternion(quat) expected = matrix33.create_from_z_rotation(np.pi) self.assertTrue(np.allclose(result, expected))
def test_create_from_z_rotation(self): result = quaternion.create_from_z_rotation(np.pi) np.testing.assert_almost_equal(result, [0.,0.,1.,0.], decimal=3) self.assertTrue(result.dtype == np.float)
def test_apply_to_vector_z(self): quat = quaternion.create_from_z_rotation(np.pi / 2.) self.assertTrue(np.allclose(quaternion.apply_to_vector(quat,[1.,0.,0.]), [0.,-1.,0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(quat,[0.,1.,0.]), [1.,0.,0.])) self.assertTrue(np.allclose(quaternion.apply_to_vector(quat,[0.,0.,1.]), [0.,0.,1.]))
def test_create_from_z_rotation(self): result = quaternion.create_from_z_rotation(np.pi) np.testing.assert_almost_equal(result, [0., 0., 1., 0.], decimal=3) self.assertTrue(result.dtype == np.float)
def __init__(self, entityName, componentInfo): Component.__init__(self, entityName, componentInfo) self.position = vector3.create(self.pos[0], self.pos[1], self.pos[2]) self.rotation = quaternion.create_from_z_rotation(self.rotAngle) self.worldMatrix = matrix44.create_identity() self.dirty = True
def SetRotation(self, angle): self.rotation = quaternion.create_from_z_rotation(self.rotAngle)