def rot33(magnitude, direction) -> numpy.float32: """Return the 3x3 matrix of float32 which rotates by the given magnitude and direction. """ return matrix33.create_from_axis_rotation(AXIS.dot( matrix33.create_from_z_rotation(direction)), magnitude, dtype=numpy.float32)
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 rotated_z(): mat = matrix33.create_from_z_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_z_rotation( theta ): """Creates a matrix with the specified rotation about the Z axis. :param float theta: The rotation, in radians, about the Z-axis. :rtype: numpy.array :return: A matrix with the shape (4,4) with the specified rotation about the Z-axis. .. seealso:: http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions """ mat = create_identity() mat[ 0:3, 0:3 ] = matrix33.create_from_z_rotation( theta ) return mat
def test_apply_to_vector_rotated_z(self): mat = matrix33.create_from_z_rotation(np.pi) vec = vector3.unit.x result = matrix33.apply_to_vector(mat, vec) expected = -vec self.assertTrue(np.allclose(result, expected))
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): mat = matrix33.create_from_z_rotation(np.pi / 2.) self.assertTrue(np.allclose(np.dot([1., 0., 0.], mat), [0., -1., 0.])) self.assertTrue(np.allclose(np.dot([0., 1., 0.], mat), [1., 0., 0.])) self.assertTrue(np.allclose(np.dot([0., 0., 1.], mat), [0., 0., 1.]))
def test_create_from_z_rotation(self): mat = matrix33.create_from_z_rotation(np.pi / 2.) self.assertTrue(np.allclose(np.dot([1.,0.,0.], mat), [0.,-1.,0.])) self.assertTrue(np.allclose(np.dot([0.,1.,0.], mat), [1.,0.,0.])) self.assertTrue(np.allclose(np.dot([0.,0.,1.], mat), [0.,0.,1.]))