Exemplo n.º 1
0
    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.)
Exemplo n.º 2
0
    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.)
Exemplo n.º 3
0
    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.]))
Exemplo n.º 4
0
    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.]))
Exemplo n.º 5
0
        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"
                )
Exemplo n.º 6
0
 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.]))
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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
Exemplo n.º 10
0
 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))
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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.]))
Exemplo n.º 13
0
 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))
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
	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
Exemplo n.º 16
0
	def SetRotation(self, angle):
		self.rotation = quaternion.create_from_z_rotation(self.rotAngle)