Пример #1
0
        def rotated_y():
            quat = quaternion.create_from_y_rotation( math.pi )
            result = matrix33.create_from_quaternion( quat )

            expected = matrix33.create_from_y_rotation( math.pi )

            self.assertTrue(
                numpy.allclose( result, expected ),
                "Matrix33 from quaternion incorrect with PI rotation about Y"
                )
Пример #2
0
        def rotated_y():
            mat = matrix33.create_from_y_rotation( math.pi )
            vec = vector3.unit.x

            result = matrix33.apply_to_vector( mat, vec )

            expected = -vec

            self.assertTrue(
                numpy.allclose( result, expected ),
                "Matrix33 apply_to_vector incorrect with rotation about Y"
                )
Пример #3
0
def create_from_y_rotation( theta ):
    """Creates a matrix with the specified rotation about the Y axis.

    :param float theta: The rotation, in radians, about the Y-axis.
    :rtype: numpy.array
    :return: A matrix with the shape (4,4) with the specified rotation about
        the Y-axis.
    
    .. seealso:: http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions
    """
    mat = create_identity()
    mat[ 0:3, 0:3 ] = matrix33.create_from_y_rotation( theta )
    return mat
Пример #4
0
 def test_inverse(self):
     m = matrix33.create_from_y_rotation(np.pi)
     result = matrix33.inverse(m)
     self.assertTrue(
         np.allclose(result, matrix33.create_from_y_rotation(-np.pi)))
Пример #5
0
 def test_apply_to_vector_rotated_y(self):
     mat = matrix33.create_from_y_rotation(np.pi)
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = -vec
     self.assertTrue(np.allclose(result, expected))
Пример #6
0
 def test_multiply_rotation(self):
     m1 = matrix33.create_from_x_rotation(np.pi)
     m2 = matrix33.create_from_y_rotation(np.pi / 2.0)
     result = matrix33.multiply(m1, m2)
     self.assertTrue(np.allclose(result, np.dot(m1, m2)))
Пример #7
0
 def test_create_from_y_rotation(self):
     mat = matrix33.create_from_y_rotation(np.pi / 2.)
     self.assertTrue(np.allclose(np.dot([1., 0., 0.], mat), [0., 0., 1.]))
     self.assertTrue(np.allclose(np.dot([0., 1., 0.], mat), [0., 1., 0.]))
     self.assertTrue(np.allclose(np.dot([0., 0., 1.], mat), [-1., 0., 0.]))
Пример #8
0
 def test_create_from_quaternion_rotated_y(self):
     quat = quaternion.create_from_y_rotation(np.pi)
     result = matrix33.create_from_quaternion(quat)
     expected = matrix33.create_from_y_rotation(np.pi)
     self.assertTrue(np.allclose(result, expected))
Пример #9
0
 def test_inverse(self):
     m = matrix33.create_from_y_rotation(np.pi)
     result = matrix33.inverse(m)
     self.assertTrue(np.allclose(result, matrix33.create_from_y_rotation(-np.pi)))
Пример #10
0
 def test_multiply_rotation(self):
     m1 = matrix33.create_from_x_rotation(np.pi)
     m2 = matrix33.create_from_y_rotation(np.pi / 2.0)
     result = matrix33.multiply(m1, m2)
     self.assertTrue(np.allclose(result, np.dot(m1,m2)))
Пример #11
0
 def test_apply_to_vector_rotated_y(self):
     mat = matrix33.create_from_y_rotation(np.pi)
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = -vec
     self.assertTrue(np.allclose(result, expected))
Пример #12
0
 def test_create_from_quaternion_rotated_y(self):
     quat = quaternion.create_from_y_rotation(np.pi)
     result = matrix33.create_from_quaternion(quat)
     expected = matrix33.create_from_y_rotation(np.pi)
     self.assertTrue(np.allclose(result, expected))
Пример #13
0
 def test_create_from_y_rotation(self):
     mat = matrix33.create_from_y_rotation(np.pi / 2.)
     self.assertTrue(np.allclose(np.dot([1.,0.,0.], mat), [0.,0.,1.]))
     self.assertTrue(np.allclose(np.dot([0.,1.,0.], mat), [0.,1.,0.]))
     self.assertTrue(np.allclose(np.dot([0.,0.,1.], mat), [-1.,0.,0.]))