Beispiel #1
0
  def test_inverse_normalized_random(self):
    """Tests that the inverse function returns normalized quaternions."""
    random_quaternion = test_helpers.generate_random_test_quaternions()

    inverse_quaternion = quaternion.inverse(random_quaternion)

    self.assertAllEqual(
        quaternion.is_normalized(inverse_quaternion),
        np.ones(shape=random_quaternion.shape[:-1] + (1,), dtype=bool))
Beispiel #2
0
  def test_from_rotation_matrix_normalized_random(self):
    """Tests that from_rotation_matrix produces normalized quaternions."""
    random_matrix = test_helpers.generate_random_test_rotation_matrix_3d()

    random_quaternion = quaternion.from_rotation_matrix(random_matrix)

    self.assertAllEqual(
        quaternion.is_normalized(random_quaternion),
        np.ones(shape=random_matrix.shape[:-2] + (1,), dtype=bool))
Beispiel #3
0
  def test_from_axis_angle_normalized_random(self):
    """Test that from_axis_angle produces normalized quaternions."""
    random_axis, random_angle = test_helpers.generate_random_test_axis_angle()

    random_quaternion = quaternion.from_axis_angle(random_axis, random_angle)

    self.assertAllEqual(
        quaternion.is_normalized(random_quaternion),
        np.ones(shape=random_angle.shape, dtype=bool))
    def test_from_euler_normalized_random(self):
        """Tests that quaternions.from_euler returns normalized quaterions."""
        random_euler_angles = test_helpers.generate_random_test_euler_angles()
        tensor_shape = random_euler_angles.shape[:-1]

        random_quaternion = quaternion.from_euler(random_euler_angles)

        self.assertAllEqual(quaternion.is_normalized(random_quaternion),
                            np.ones(shape=tensor_shape + (1, ), dtype=bool))
Beispiel #5
0
  def test_normalize_random(self):
    """Tests that normalize works as intended."""
    random_quaternion = test_helpers.generate_random_test_quaternions()
    tensor_shape = random_quaternion.shape[:-1]

    unnormalized_random_quaternion = random_quaternion * 1.01
    quat = np.concatenate((random_quaternion, unnormalized_random_quaternion),
                          axis=0)
    mask = np.concatenate(
        (np.ones(shape=tensor_shape + (1,),
                 dtype=bool), np.zeros(shape=tensor_shape + (1,), dtype=bool)),
        axis=0)
    is_normalized_before = quaternion.is_normalized(quat)
    normalized = quaternion.normalize(quat)
    is_normalized_after = quaternion.is_normalized(normalized)

    self.assertAllEqual(mask, is_normalized_before)
    self.assertAllEqual(is_normalized_after,
                        np.ones(shape=is_normalized_after.shape, dtype=bool))
    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))