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" )
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" )
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
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)))
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))
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)))
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.]))
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))
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)))
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)))
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.]))