Пример #1
0
 def test_between_two_vectors_3d_that_are_collinear(self):
   """Checks the extracted rotation between two collinear 3d vectors."""
   axis = [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0)]
   antiparallel_axis = [(0.0, 1.0, 0.0), (0.0, 0.0, 1.0)]
   source = np.multiply(axis, 10.)
   target = np.multiply(axis, -10.)
   rotation = quaternion.between_two_vectors_3d(source, target)
   rotation_pi = quaternion.from_axis_angle(antiparallel_axis,
                                            [[np.pi], [np.pi]])
   self.assertAllClose(rotation_pi, rotation)
Пример #2
0
  def test_between_two_vectors_3d_jacobian_random(self):
    """Tests the Jacobian of between_two_vectors_3d."""
    tensor_size = np.random.randint(3)
    tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist()
    x_1_init = np.random.random(tensor_shape + [3])
    x_2_init = np.random.random(tensor_shape + [3])
    x_1 = tf.convert_to_tensor(value=x_1_init)
    x_2 = tf.convert_to_tensor(value=x_2_init)

    y = quaternion.between_two_vectors_3d(x_1, x_2)

    self.assert_jacobian_is_correct(x_1, x_1_init, y, atol=1e-4)
    self.assert_jacobian_is_correct(x_2, x_2_init, y, atol=1e-4)
Пример #3
0
    def test_between_two_vectors_3d_random(self):
        """Checks the extracted rotation between two 3d vectors."""
        tensor_size = np.random.randint(3)
        tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist()
        source = np.random.random(tensor_shape + [3]).astype(np.float32)
        target = np.random.random(tensor_shape + [3]).astype(np.float32)

        rotation = quaternion.between_two_vectors_3d(source, target)
        rec_target = quaternion.rotate(source, rotation)

        self.assertAllClose(tf.nn.l2_normalize(target, axis=-1),
                            tf.nn.l2_normalize(rec_target, axis=-1))
        # Checks that resulting quaternions are normalized.
        self.assertAllEqual(quaternion.is_normalized(rotation),
                            np.full(tensor_shape + [1], True))
Пример #4
0
 def test_between_two_vectors_3d_that_are_the_same(self):
   """Checks the extracted rotation between two identical 3d vectors."""
   source = np.random.random((1, 3))
   rotation = quaternion.between_two_vectors_3d(source, source)
   self.assertAllEqual([[0, 0, 0, 1]], rotation)