def test_interpolated_rotations(self): x = Rotation.from_axis_angle([1, 0, 0], 0) a = math.pi / 2 y = Rotation.from_axis_angle([0, 1, 0], a) i_list = Rotation.interpolated_rotations(x, y, 3) nose.tools.assert_equal([i._ctype for i in i_list], ['d'] * 3) i0_e_axis, i0_e_angle = [0, 1, 0], a * 0.25 i1_e_axis, i1_e_angle = [0, 1, 0], a * 0.50 i2_e_axis, i2_e_angle = [0, 1, 0], a * 0.75 numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14) numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 14) numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14) numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 14) numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14) numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 14) # Mixed types a = math.pi / 2 x = Rotation.from_axis_angle([1, 0, 0], 0, 'f') y = Rotation.from_axis_angle([0, 1, 0], a) i_list = Rotation.interpolated_rotations(x, y, 3) nose.tools.assert_equal([i._ctype for i in i_list], ['f'] * 3) numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14) numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 6) numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14) numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 6) numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14) numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 6)
def test_translation_initialized(self): center = EigenArray.from_array([[1],[2],[3]]) rotation = Rotation.from_axis_angle([0, 1, 0], math.pi / 2.) cam = Camera(center, rotation) numpy.testing.assert_array_equal( cam.translation, -(rotation * center.get_matrix()) )
def test_from_aa(self): # Axis should come out of rotation normalized angle = 0.8 axis = numpy.array([[-3], [2], [1]]) axis_norm = axis / numpy.linalg.norm(axis) r = Rotation.from_axis_angle(axis, angle) nose.tools.assert_equal(angle, r.angle()) numpy.testing.assert_equal(axis_norm, r.axis())
def test_from_aa(self): # Axis should come out of rotation normalized angle = 0.8 axis = [-3,2,1] axis_norm = array_normalize(axis) r = Rotation.from_axis_angle(axis, angle) nose.tools.assert_equal(angle, r.angle()) numpy.testing.assert_equal(axis_norm, r.axis())
def test_from_aa(self): # Axis should come out of rotation normalized angle = 0.8 axis = [-3, 2, 1] axis_norm = array_normalize(axis) r = Rotation.from_axis_angle(axis, angle) nose.tools.assert_equal(angle, r.angle()) numpy.testing.assert_equal(axis_norm, r.axis())
def test_from_aa(self): # Axis should come out of rotation normalized angle = 0.8 axis = numpy.array([[-3], [2], [1]]) axis_norm = axis / numpy.linalg.norm(axis) r = Rotation.from_axis_angle(axis, angle) nose.tools.assert_equal(angle, r.angle()) numpy.testing.assert_equal(axis_norm, r.axis())
def test_equal(self): cam1 = Camera() cam2 = Camera() nose.tools.assert_equal(cam1, cam1) nose.tools.assert_equal(cam1, cam2) center = EigenArray.from_iterable([[1], [2], [3]]) rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.) cam1 = Camera(center, rotation) cam2 = Camera(center, rotation) nose.tools.assert_equal(cam1, cam1) nose.tools.assert_equal(cam1, cam2)
def test_equal(self): cam1 = Camera() cam2 = Camera() nose.tools.assert_equal(cam1, cam1) nose.tools.assert_equal(cam1, cam2) center = EigenArray.from_array([[1],[2],[3]]) rotation = Rotation.from_axis_angle([0, 1, 0], math.pi / 2.) cam1 = Camera(center, rotation) cam2 = Camera(center, rotation) nose.tools.assert_equal(cam1, cam1) nose.tools.assert_equal(cam1, cam2)
def test_interpolation(self): x_d = Rotation.from_axis_angle([1, 0, 0], 0, 'd') y_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'd') r_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'd') x_f = Rotation.from_axis_angle([1, 0, 0], 0, 'f') y_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'f') r_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'f') z_d = Rotation.interpolate(x_d, y_d, 0.5) z_f = Rotation.interpolate(x_f, y_f, 0.5) nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14) nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6) # Should auto-convert different y-type into x's type for computation. # Return should be of x's type. z_d = Rotation.interpolate(x_d, y_f, 0.5) nose.tools.assert_is(z_d._ctype, x_d._ctype) nose.tools.assert_is_not(z_d._ctype, y_f._ctype) nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14) z_f = Rotation.interpolate(x_f, y_d, 0.5) nose.tools.assert_is(z_f._ctype, x_f._ctype) nose.tools.assert_is_not(z_f._ctype, y_d._ctype) nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6)
def test_interpolation(self): x_d = Rotation.from_axis_angle([1, 0, 0], 0, 'd') y_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'd') r_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'd') x_f = Rotation.from_axis_angle([1, 0, 0], 0, 'f') y_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'f') r_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'f') z_d = Rotation.interpolate(x_d, y_d, 0.5) z_f = Rotation.interpolate(x_f, y_f, 0.5) nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14) nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6) # Should auto-convert different y-type into x's type for computation. # Return should be of x's type. z_d = Rotation.interpolate(x_d, y_f, 0.5) nose.tools.assert_is(z_d._ctype, x_d._ctype) nose.tools.assert_is_not(z_d._ctype, y_f._ctype) nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14) z_f = Rotation.interpolate(x_f, y_d, 0.5) nose.tools.assert_is(z_f._ctype, x_f._ctype) nose.tools.assert_is_not(z_f._ctype, y_d._ctype) nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6)
def test_interpolated_rotations(self): x = Rotation.from_axis_angle([1, 0, 0], 0) a = math.pi / 2 y = Rotation.from_axis_angle([0, 1, 0], a) i_list = Rotation.interpolated_rotations(x, y, 3) nose.tools.assert_equal([i._ctype for i in i_list], ['d'] * 3) i0_e_axis, i0_e_angle = [0, 1, 0], a * 0.25 i1_e_axis, i1_e_angle = [0, 1, 0], a * 0.50 i2_e_axis, i2_e_angle = [0, 1, 0], a * 0.75 numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14) numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 14) numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14) numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 14) numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14) numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 14) # Mixed types a = math.pi / 2 x = Rotation.from_axis_angle([1, 0, 0], 0, 'f') y = Rotation.from_axis_angle([0, 1, 0], a) i_list = Rotation.interpolated_rotations(x, y, 3) nose.tools.assert_equal([i._ctype for i in i_list], ['f'] * 3) numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14) numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 6) numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14) numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 6) numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14) numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 6)
def test_rotation_vector(self): vec = [1, 0, 0] vec_expected = [0, 1, 0] r_axis = [0, 0, 1] r_angle = math.pi / 2. r = Rotation.from_axis_angle(r_axis, r_angle) vec_rotated = r.rotate_vector(vec) numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated) # should be able to multiply a rotation as a left-hand side arg with a # 3x1 vector as the right-hand side arg vec_rotated = r * vec numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated)
def test_rotation_vector(self): vec = [1, 0, 0] vec_expected = [0, 1, 0] r_axis = [0, 0, 1] r_angle = math.pi / 2. r = Rotation.from_axis_angle(r_axis, r_angle) vec_rotated = r.rotate_vector(vec) numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated) # should be able to multiply a rotation as a left-hand side arg with a # 3x1 vector as the right-hand side arg vec_rotated = r * vec numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated)
def test_to_from_string(self): cam = Camera() cam_s = cam.as_string() cam2 = Camera.from_string(cam_s) print "Default camera string:\n%s" % cam_s print "Default newcam string:\n%s" % cam2.as_string() nose.tools.assert_equal(cam, cam2) center = EigenArray.from_iterable([[1], [2], [3]]) rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.) cam = Camera(center, rotation) cam_s = cam.as_string() cam2 = Camera.from_string(cam_s) print "Custom camera string:\n%s" % cam_s print "Custom newcam string:\n%s" % cam2.as_string() nose.tools.assert_equal(cam, cam2)
def test_to_from_string(self): cam = Camera() cam_s = cam.as_string() cam2 = Camera.from_string(cam_s) print "Default camera string:\n%s" % cam_s print "Default newcam string:\n%s" % cam2.as_string() nose.tools.assert_equal(cam, cam2) center = EigenArray.from_iterable([[1], [2], [3]]) rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.) cam = Camera(center, rotation) cam_s = cam.as_string() cam2 = Camera.from_string(cam_s) print "Custom camera string:\n%s" % cam_s print "Custom newcam string:\n%s" % cam2.as_string() nose.tools.assert_equal(cam, cam2)
def test_rotation_initialized(self): r_expected = Rotation.from_axis_angle([[0],[1],[0]], math.pi / 8) cam = Camera(rotation=r_expected) nose.tools.assert_is_not(cam.rotation, r_expected) nose.tools.assert_equal(cam.rotation, r_expected)
def test_rotation_initialized(self): r_expected = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 8) cam = Camera(rotation=r_expected) nose.tools.assert_is_not(cam.rotation, r_expected) nose.tools.assert_equal(cam.rotation, r_expected)
def test_translation_initialized(self): center = EigenArray.from_iterable([[1], [2], [3]]) rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.) cam = Camera(center, rotation) numpy.testing.assert_array_equal(cam.translation, -(rotation * center))
def test_rotation_initialized(self): center = EigenArray.from_array([[1], [2], [3]]) r_expected = Rotation.from_axis_angle([0, 1, 0], math.pi / 8) cam = Camera(center, r_expected) nose.tools.assert_is_not(cam.rotation, r_expected) nose.tools.assert_equal(cam.rotation, r_expected)
def test_rotation_initialized(self): center = EigenArray.from_array([[1],[2],[3]]) r_expected = Rotation.from_axis_angle([0,1,0], math.pi / 8) cam = Camera(center, r_expected) nose.tools.assert_is_not(cam.rotation, r_expected) nose.tools.assert_equal(cam.rotation, r_expected)