def test_is_valid_random(self):
        """Tests that is_valid works as intended."""
        random_euler_angle = test_helpers.generate_random_test_euler_angles()
        tensor_tile = random_euler_angle.shape[:-1]

        rotation_matrix = rotation_matrix_3d.from_euler(random_euler_angle)
        pred_normalized = rotation_matrix_3d.is_valid(rotation_matrix)

        with self.subTest(name="all_normalized"):
            self.assertAllEqual(pred_normalized,
                                np.ones(shape=tensor_tile + (1, ), dtype=bool))

        with self.subTest(name="non_orthonormal"):
            test_matrix = np.array([[2., 0., 0.], [0., 0.5, 0], [0., 0., 1.]])
            pred_normalized = rotation_matrix_3d.is_valid(test_matrix)

            self.assertAllEqual(pred_normalized,
                                np.zeros(shape=(1, ), dtype=bool))

        with self.subTest(name="negative_orthonormal"):
            test_matrix = np.array([[1., 0., 0.], [0., -1., 0.], [0., 0., 1.]])
            pred_normalized = rotation_matrix_3d.is_valid(test_matrix)

            self.assertAllEqual(pred_normalized,
                                np.zeros(shape=(1, ), dtype=bool))
    def test_from_euler_normalized_random(self):
        """Tests that euler angles can be converted to rotation matrices."""
        random_euler_angles = test_helpers.generate_random_test_euler_angles()

        matrix = rotation_matrix_3d.from_euler(random_euler_angles)

        self.assertAllEqual(rotation_matrix_3d.is_valid(matrix),
                            np.ones(random_euler_angles.shape[0:-1] + (1, )))
    def test_from_quaternion_normalized_random(self):
        """Tests that random quaternions can be converted to rotation matrices."""
        random_quaternion = test_helpers.generate_random_test_quaternions()
        tensor_shape = random_quaternion.shape[:-1]

        random_matrix = rotation_matrix_3d.from_quaternion(random_quaternion)

        self.assertAllEqual(rotation_matrix_3d.is_valid(random_matrix),
                            np.ones(tensor_shape + (1, )))
    def test_from_quaternion_normalized_preset(self):
        """Tests that quaternions can be converted to rotation matrices."""
        euler_angles = test_helpers.generate_preset_test_euler_angles()

        quat = quaternion.from_euler(euler_angles)
        matrix_quat = rotation_matrix_3d.from_quaternion(quat)

        self.assertAllEqual(rotation_matrix_3d.is_valid(matrix_quat),
                            np.ones(euler_angles.shape[0:-1] + (1, )))
    def test_from_axis_angle_normalized_preset(self):
        """Tests that axis-angles can be converted to rotation matrices."""
        euler_angles = test_helpers.generate_preset_test_euler_angles()

        axis, angle = axis_angle.from_euler(euler_angles)
        matrix_axis_angle = rotation_matrix_3d.from_axis_angle(axis, angle)

        self.assertAllEqual(rotation_matrix_3d.is_valid(matrix_axis_angle),
                            np.ones(euler_angles.shape[0:-1] + (1, )))
Example #6
0
  def test_inverse_normalized_random(self):
    """Checks that inverted rotation matrices are valid rotations."""
    random_euler_angle = test_helpers.generate_random_test_euler_angles()
    tensor_tile = random_euler_angle.shape[:-1]

    random_matrix = rotation_matrix_3d.from_euler(random_euler_angle)
    predicted_invert_random_matrix = rotation_matrix_3d.inverse(random_matrix)

    self.assertAllEqual(
        rotation_matrix_3d.is_valid(predicted_invert_random_matrix),
        np.ones(tensor_tile + (1,)))
    def test_from_axis_angle_normalized_random(self):
        """Tests that axis-angles can be converted to rotation matrices."""
        tensor_shape = np.random.randint(1, 10,
                                         size=np.random.randint(3)).tolist()
        random_axis = np.random.normal(size=tensor_shape + [3])
        random_axis /= np.linalg.norm(random_axis, axis=-1, keepdims=True)
        random_angle = np.random.normal(size=tensor_shape + [1])

        matrix_axis_angle = rotation_matrix_3d.from_axis_angle(
            random_axis, random_angle)

        self.assertAllEqual(rotation_matrix_3d.is_valid(matrix_axis_angle),
                            np.ones(tensor_shape + [1]))
Example #8
0
  def test_from_axis_angle_random(self):
    """Tests conversion to matrix."""
    tensor_shape = np.random.randint(1, 10, size=np.random.randint(3)).tolist()
    random_axis = np.random.normal(size=tensor_shape + [3])
    random_axis /= np.linalg.norm(random_axis, axis=-1, keepdims=True)
    random_angle = np.random.normal(size=tensor_shape + [1])

    matrix_axis_angle = rotation_matrix_3d.from_axis_angle(
        random_axis, random_angle)
    random_quaternion = quaternion.from_axis_angle(random_axis, random_angle)
    matrix_quaternion = rotation_matrix_3d.from_quaternion(random_quaternion)

    self.assertAllClose(matrix_axis_angle, matrix_quaternion, rtol=1e-3)
    # Checks that resulting rotation matrices are normalized.
    self.assertAllEqual(
        rotation_matrix_3d.is_valid(matrix_axis_angle),
        np.ones(tensor_shape + [1]))