示例#1
0
 def test_multiply(self):
     # Single
     rot = rotmodule.random()
     inv = rotmodule.inverse(rot)
     identity = numpy.array((1., 0., 0., 0.))
     numpy.testing.assert_array_almost_equal(rotmodule.multiply(rot, inv),
                                             identity)
     # Array
     rot = rotmodule.random(number_of_quaternions=10)
     inv = rotmodule.inverse(rot)
     identity = numpy.zeros((10, 4))
     identity[:, 0] = 1.
     numpy.testing.assert_array_almost_equal(rotmodule.multiply(rot, inv),
                                             identity)
示例#2
0
 def test_perturbation_no_symmetry_absolute(self):
     nrots = 100
     rotations_1 = rotmodule.random(number_of_quaternions=nrots)
     overall_rot = rotmodule.random()
     perturbation = 0.000001
     rotations_2 = rotmodule.normalize(rotations_1 + perturbation *
                                       numpy.random.random((nrots, 4)))
     repeated_overall_rot = numpy.repeat(overall_rot.reshape((1, 4)),
                                         nrots,
                                         axis=0)
     rotations_2 = rotmodule.multiply(repeated_overall_rot, rotations_2)
     avg_absolute = compare_rotations.absolute_orientation_error(
         rotations_1, rotations_2)
     self.assertLess(avg_absolute, 4. * numpy.pi / 180.)
示例#3
0
 def test_perturbation_with_symmetry_relative(self):
     nrots = 100
     rotations_1 = rotmodule.random(number_of_quaternions=nrots)
     overall_rot = rotmodule.random()
     perturbation = 0.000001
     rotations_2 = rotmodule.normalize(rotations_1 + perturbation *
                                       numpy.random.random((nrots, 4)))
     symmetry_operations = ((1., 0., 0., 0.), (0., 1., 0., 0.))
     symmetry_version = numpy.random.randint(2, size=nrots)
     for i in range(nrots):
         rotations_2[i, :] = rotmodule.multiply(
             symmetry_operations[symmetry_version[i]], rotations_2[i, :])
     repeated_overall_rot = numpy.repeat(overall_rot.reshape((1, 4)),
                                         nrots,
                                         axis=0)
     rotations_2 = rotmodule.multiply(repeated_overall_rot, rotations_2)
     avg_relative = compare_rotations.relative_orientation_error(
         rotations_1, rotations_2, symmetry_operations)
     self.assertLess(avg_relative, 5. * numpy.pi / 180.)
示例#4
0
 def test_random(self):
     """Check that all quaternions have non-negative x-component and that
     the average is close to the x-axis"""
     nrots = 100
     rots = rotmodule.random(number_of_quaternions=nrots)
     self.assertGreaterEqual(rots[:, 0].min(), 0)
     numpy.testing.assert_array_almost_equal(rots.mean(axis=0)[1:],
                                             numpy.array((
                                                 0.,
                                                 0.,
                                                 0.,
                                             )),
                                             decimal=1)
示例#5
0
 def test_fix_sign(self):
     # Single
     rot = numpy.array([-1., 0., 0., 0.])
     rotmodule.fix_sign(rot)
     self.assertGreaterEqual(rot[0], 0)
     rot = numpy.array([0., 0., 0., -1.])
     rotmodule.fix_sign(rot)
     numpy.testing.assert_array_almost_equal(rot,
                                             numpy.array([0., 0., 0., 1.]))
     # Array
     rots = rotmodule.random(100, fix_sign=False)
     rotmodule.fix_sign(rots)
     self.assertGreaterEqual(rots[:, 0].min(), 0)
示例#6
0
 def test_inverse(self):
     # Single
     rot_1 = rotmodule.from_angle_and_dir(numpy.pi / 8., (1., 0., 0.))
     rot_2 = rotmodule.from_angle_and_dir(-numpy.pi / 8., (1., 0., 0.))
     rot_1_inv = rotmodule.inverse(rot_1)
     numpy.testing.assert_array_almost_equal(rot_1_inv, rot_2)
     # Array
     rots = rotmodule.random(number_of_quaternions=10)
     inv_1 = rotmodule.inverse(rots)
     inv_2 = rots.copy()
     inv_2[:, 0] = -inv_2[:, 0]
     rotmodule.fix_sign(inv_2)
     numpy.testing.assert_array_almost_equal(inv_1, inv_2)