def testPiNegativePi(xyz, angle, axis):
    '''
    A rotation by pi should give the same result as a rotation by negative pi
    '''
    rotated_xyz_positive = coord_transforms.rotate_vector_Nd(xyz, np.pi*angle, axis)
    rotated_xyz_negative = coord_transforms.rotate_vector_Nd(xyz, -np.pi*angle, axis)
    np.testing.assert_allclose(rotated_xyz_positive, rotated_xyz_negative)
 def testNegativeRotationAxis(self):
     '''
     rotating around the rotation axis vs the negative rotation axis should rotate in opposite directions
     '''
     xyz = np.array([[0, 0, 1]])
     angle = np.pi/2
     rotation_vector = np.array([1, 1, 0])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     rotated_vector_negative = coord_transforms.rotate_vector_Nd(xyz, angle, -rotation_vector)
     np.testing.assert_array_almost_equal(rotated_vector_negative, -rotated_vector)
 def testNegativeAngle(self):
     '''
     rotating a vector by -pi/2 vs rotating by pi/2
     '''
     xyz = np.array([[1/np.sqrt(2), 1/np.sqrt(2), 0],[1.1, 1.1, 1.1]])
     angle = np.pi/2
     rotation_vector = np.array([0,0,1])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     rotated_vector_negative = coord_transforms.rotate_vector_Nd(xyz, -angle, rotation_vector)
     np.testing.assert_array_almost_equal(rotated_vector_negative, np.array([[-1, -1, 1]])*rotated_vector)
def testVectorMagnitude(xyz, angle, axis):
    '''
    The magnitude of a vector should be the same before and after it is rotated
    '''
    xyz_mag = np.sqrt(np.sum(np.square(xyz)))
    rotated_xyz = coord_transforms.rotate_vector_Nd(xyz, angle, axis)
    rotated_mag = np.sqrt(np.sum(np.square(rotated_xyz)))
    np.testing.assert_allclose(xyz_mag, rotated_mag)
 def testTiltedRotationAxis(self):
     '''
     the rotation axis is tilted off one of the main axes
     '''
     xyz = np.array([[0, 0, 1]])
     angle = np.pi/2
     rotation_vector = np.array([1, 1, 0])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     np.testing.assert_array_almost_equal(np.array([[1/np.sqrt(2), -1/np.sqrt(2), 0]]), rotated_vector)
 def testRotationAxisHighMagnitude(self):
     '''
     the input rotation axis has a magnitude that is not 1
     '''
     xyz = np.array([[1/np.sqrt(2), 1/np.sqrt(2), 0],[1.1, 1.1, 1.1]])
     angle = np.pi
     rotation_vector = np.array([0,0,3])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     np.testing.assert_array_almost_equal(np.array([-1, -1, 1])*xyz, rotated_vector)
 def testAnglesMultiplesOfPi(self):
     '''
     rotating a vector by an angle that is a multiple of pi
     '''
     xyz = np.array([[1/np.sqrt(2), 1/np.sqrt(2), 0],[1.1, 1.1, 1.1]])
     angle = np.pi
     rotation_vector = np.array([0,0,1])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     np.testing.assert_array_almost_equal(np.array([-1, -1, 1])*xyz, rotated_vector)
 def testAnglesGreater2Pi(self):
     '''
     rotating a vector by an angle greater than 2pi
     '''
     xyz = np.array([[1/np.sqrt(2), 1/np.sqrt(2), 0],[1.1, 1.1, 1.1]])
     angle = np.pi/2+2*np.pi
     rotation_vector = np.array([0,0,1])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     np.testing.assert_array_almost_equal(np.array([[-1/np.sqrt(2), 1/np.sqrt(2), 0], [-1.1, 1.1, 1.1]]), rotated_vector)
 def testFloatsVectorsRotateBy90(self):
     '''
     take (0.707, 0.707, 0), (1, 1, 1) and rotate around (0,0,1) by pi/2
     '''
     xyz = np.array([[1/np.sqrt(2), 1/np.sqrt(2), 0],[1.1, 1.1, 1.1]])
     angle = np.pi/2
     rotation_vector = np.array([0,0,1])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     np.testing.assert_array_almost_equal(np.array([[-1/np.sqrt(2), 1/np.sqrt(2), 0], [-1.1, 1.1, 1.1]]), rotated_vector)
 def testAxisVectorsRotateBy90(self):
     '''
     take (0,1,0), (1, 0, 0) and (0,0,1) and rotate around (0,0,1) by pi/2
     '''
     xyz = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]])
     angle = np.pi/2
     rotation_vector = np.array([0,0,1])
     rotated_vector = coord_transforms.rotate_vector_Nd(xyz, angle, rotation_vector)
     np.testing.assert_array_almost_equal(np.array([[-1, 0, 0],[0, 1, 0],[0, 0, 1]]), rotated_vector)
def testDotProduct(xyz, angle, axis):
    '''
    The dot product of the vector onto the rotation axis should be the same 
    before and after rotation
    '''
    xyz_dot = np.dot(xyz, axis)
    rotated_xyz = coord_transforms.rotate_vector_Nd(xyz, angle, axis)
    rotated_dot = np.dot(rotated_xyz, axis)
    np.testing.assert_allclose(xyz_dot, rotated_dot)
def testRotate2Pi(xyz, angle, axis):
    '''
    A rotation of a vector by an integer multiple of 2pi should return the same vector
    '''
    rotated_xyz = coord_transforms.rotate_vector_Nd(xyz, 2*np.pi*angle, axis)
    np.testing.assert_allclose(xyz, rotated_xyz, atol=1e-7)