Exemplo n.º 1
0
 def test_local_transform(self):
     R = moveable._rotation_matrix_from_angles(*self.rotation_angles, 
                                      dummy_dimension=True)
     T = moveable._translation_matrix_from_vector(self.translation)
     L_ref = np.dot(T, R)
     L_ans = self.PAS.local_transform
     np.testing.assert_array_almost_equal(L_ref, L_ans)
Exemplo n.º 2
0
 def test_local_transform(self):
     R = moveable._rotation_matrix_from_angles(*self.rotation_angles,
                                               dummy_dimension=True)
     T = moveable._translation_matrix_from_vector(self.translation)
     L_ref = np.dot(T, R)
     L_ans = self.PAS.local_transform
     np.testing.assert_array_almost_equal(L_ref, L_ans)
Exemplo n.º 3
0
def test_rotation_matrix_from_angles():
    
    x = np.array([1.0, 0.0, 0.0]) # vector pointing at x
    
    Rz = moveable._rotation_matrix_from_angles(90.0, 0.0, 0.0)
    y = np.dot(Rz, x)
    np.testing.assert_array_almost_equal(y, np.array([0.0, 1.0, 0.0]),
                                         err_msg='Rz err')
    
    Rx = moveable._rotation_matrix_from_angles(0.0, 0.0, 90.0)
    z = np.dot(Rx, y)
    np.testing.assert_array_almost_equal(z, np.array([0.0, 0.0, 1.0]),
                                         err_msg='Rx err')
    
    Ry = moveable._rotation_matrix_from_angles(0.0, -90.0, 0.0)
    x = np.dot(Ry, z)
    np.testing.assert_array_almost_equal(x, x, err_msg='Ry err')
Exemplo n.º 4
0
def test_rotation_matrix_from_angles():

    x = np.array([1.0, 0.0, 0.0])  # vector pointing at x

    Rz = moveable._rotation_matrix_from_angles(90.0, 0.0, 0.0)
    y = np.dot(Rz, x)
    np.testing.assert_array_almost_equal(y,
                                         np.array([0.0, 1.0, 0.0]),
                                         err_msg='Rz err')

    Rx = moveable._rotation_matrix_from_angles(0.0, 0.0, 90.0)
    z = np.dot(Rx, y)
    np.testing.assert_array_almost_equal(z,
                                         np.array([0.0, 0.0, 1.0]),
                                         err_msg='Rx err')

    Ry = moveable._rotation_matrix_from_angles(0.0, -90.0, 0.0)
    x = np.dot(Ry, z)
    np.testing.assert_array_almost_equal(x, x, err_msg='Ry err')
Exemplo n.º 5
0
def test_angle_retrieval():

    for i in range(100):

        alpha = np.random.rand() * 180.0
        beta  = np.random.rand() * 180.0
        gamma = np.random.rand() * 180.0

        R = moveable._rotation_matrix_from_angles(gamma, beta, alpha)

        I = np.eye(3)
        Ip = np.dot(R, I)

        gp, bp, ap = moveable._angles_from_rotated_frame(Ip[:,0], Ip[:,1], Ip[:,2])

        #print np.array([gamma, beta, alpha]), np.array([gp, bp, ap])

        # test to make sure they rotate to the same thing
        R2 = moveable._rotation_matrix_from_angles(gp, bp, ap)

        assert np.sum( np.abs( R - R2 ) ) < 1e-12
Exemplo n.º 6
0
def test_angle_retrieval():

    for i in range(100):

        alpha = np.random.rand() * 180.0
        beta = np.random.rand() * 180.0
        gamma = np.random.rand() * 180.0

        R = moveable._rotation_matrix_from_angles(gamma, beta, alpha)

        I = np.eye(3)
        Ip = np.dot(R, I)

        gp, bp, ap = moveable._angles_from_rotated_frame(
            Ip[:, 0], Ip[:, 1], Ip[:, 2])

        #print np.array([gamma, beta, alpha]), np.array([gp, bp, ap])

        # test to make sure they rotate to the same thing
        R2 = moveable._rotation_matrix_from_angles(gp, bp, ap)

        assert np.sum(np.abs(R - R2)) < 1e-12
Exemplo n.º 7
0
    def test_xyz(self):

        uxyz = self.PAS.untransformed_xyz

        buff = np.ones(list(uxyz.shape[:-1]) + [1], dtype=uxyz.dtype)
        uxyzd = np.concatenate([uxyz, buff], axis=-1)

        R = moveable._rotation_matrix_from_angles(*self.rotation_angles,
                                                  dummy_dimension=True)
        T = moveable._translation_matrix_from_vector(self.translation)

        xyz_ans = np.dot(uxyzd, np.dot(T, R).T)
        np.testing.assert_array_almost_equal(self.PAS.xyz, xyz_ans[..., :3])
Exemplo n.º 8
0
 def test_xyz(self):
     
     uxyz = self.PAS.untransformed_xyz
     
     buff = np.ones( list(uxyz.shape[:-1]) + [1], dtype=uxyz.dtype)
     uxyzd = np.concatenate([uxyz, buff], axis=-1)
     
     R = moveable._rotation_matrix_from_angles(*self.rotation_angles, 
                                               dummy_dimension=True)
     T = moveable._translation_matrix_from_vector(self.translation)
     
     xyz_ans = np.dot(uxyzd, np.dot(T, R).T)
     np.testing.assert_array_almost_equal(self.PAS.xyz, xyz_ans[...,:3])
Exemplo n.º 9
0
 def test_global_transform(self):
     
     ra_p = np.random.rand(3) * 360.0
     t_p  = np.random.randn(3)
     
     Rp = moveable._rotation_matrix_from_angles(*ra_p, dummy_dimension=True)
     Tp = moveable._translation_matrix_from_vector(t_p)
     
     parent_obj = camera.CompoundCamera(type_name='daddy', 
                                            id_num=0, parent=None,
                                            rotation_angles=ra_p, 
                                            translation=t_p)
                                   
     self.PAS.set_parent(parent_obj)
     
     R = moveable._rotation_matrix_from_angles(*self.rotation_angles, 
                                      dummy_dimension=True)
     T = moveable._translation_matrix_from_vector(self.translation)
     
     G_ref = np.dot( np.dot( np.dot(Tp, Rp), T), R) # T_1 . R_1 . T_2 . R_2
     G_ans = self.PAS.global_transform
     
     np.testing.assert_array_almost_equal(G_ref, G_ans)
Exemplo n.º 10
0
    def test_global_transform(self):

        ra_p = np.random.rand(3) * 360.0
        t_p = np.random.randn(3)

        Rp = moveable._rotation_matrix_from_angles(*ra_p, dummy_dimension=True)
        Tp = moveable._translation_matrix_from_vector(t_p)

        parent_obj = camera.CompoundCamera(type_name='daddy',
                                           id_num=0,
                                           parent=None,
                                           rotation_angles=ra_p,
                                           translation=t_p)

        self.PAS.set_parent(parent_obj)

        R = moveable._rotation_matrix_from_angles(*self.rotation_angles,
                                                  dummy_dimension=True)
        T = moveable._translation_matrix_from_vector(self.translation)

        G_ref = np.dot(np.dot(np.dot(Tp, Rp), T), R)  # T_1 . R_1 . T_2 . R_2
        G_ans = self.PAS.global_transform

        np.testing.assert_array_almost_equal(G_ref, G_ans)
Exemplo n.º 11
0
 def test_evaluate_transform(self):
 
     # for rotation
     x = np.array([[1.0, 0.0, 0.0]]) # vector pointing at x
     Rz = moveable._rotation_matrix_from_angles(90.0, 0.0, 0.0, 
                                                dummy_dimension=True)                                         
     ref = np.array([[0.0, 1.0, 0.0]])
     ans = camera.CompoundCamera._evaluate_transform(Rz, x)
     np.testing.assert_array_almost_equal(ans, ref, err_msg='rotation')
                                      
     # for translation
     x = np.random.randint(0,5,size=(1,3))    
     y = np.random.randint(0,5,size=(1,3))    
     T = moveable._translation_matrix_from_vector(x)    
     assert np.all( camera.CompoundCamera._evaluate_transform(T, y) == x + y )
Exemplo n.º 12
0
    def test_evaluate_transform(self):

        # for rotation
        x = np.array([[1.0, 0.0, 0.0]])  # vector pointing at x
        Rz = moveable._rotation_matrix_from_angles(90.0,
                                                   0.0,
                                                   0.0,
                                                   dummy_dimension=True)
        ref = np.array([[0.0, 1.0, 0.0]])
        ans = camera.CompoundCamera._evaluate_transform(Rz, x)
        np.testing.assert_array_almost_equal(ans, ref, err_msg='rotation')

        # for translation
        x = np.random.randint(0, 5, size=(1, 3))
        y = np.random.randint(0, 5, size=(1, 3))
        T = moveable._translation_matrix_from_vector(x)
        assert np.all(camera.CompoundCamera._evaluate_transform(T, y) == x + y)