def test_from_euler_with_small_angles_approximation_random(self): # Only generate small angles. For a test tolerance of 1e-3, 0.23 was found # empirically to be the range where the small angle approximation works. random_euler_angles = test_helpers.generate_random_test_euler_angles( min_angle=-0.23, max_angle=0.23) exact_axis_angle = axis_angle.from_euler(random_euler_angles) approximate_axis_angle = ( axis_angle.from_euler_with_small_angles_approximation( random_euler_angles)) self.assertAllClose(exact_axis_angle, approximate_axis_angle, atol=1e-3)
def test_from_euler_random(self): """Tests that from_euler allows to perform the expect rotation of points.""" random_euler_angles = test_helpers.generate_random_test_euler_angles() tensor_shape = random_euler_angles.shape[:-1] random_point = np.random.normal(size=tensor_shape + (3, )) random_matrix = rotation_matrix_3d.from_euler(random_euler_angles) random_axis, random_angle = axis_angle.from_euler(random_euler_angles) rotated_with_matrix = rotation_matrix_3d.rotate( random_point, random_matrix) rotated_with_axis_angle = axis_angle.rotate(random_point, random_axis, random_angle) self.assertAllClose(rotated_with_matrix, rotated_with_axis_angle)
def test_from_axis_angle_gimbal(self, gimbal_configuration): """Checks that from_axis_angle works when Ry = pi/2 or -pi/2.""" random_euler_angles = test_helpers.generate_random_test_euler_angles() random_euler_angles[..., 1] = gimbal_configuration random_matrix = rotation_matrix_3d.from_euler(random_euler_angles) random_axis, random_angle = axis_angle.from_euler(random_euler_angles) predicted_random_angles = euler.from_axis_angle( random_axis, random_angle) reconstructed_random_matrices = rotation_matrix_3d.from_euler( predicted_random_angles) self.assertAllClose(reconstructed_random_matrices, random_matrix, atol=1e-3)
def test_is_normalized_random(self): """Tests that is_normalized works as intended.""" # Samples normalized axis-angles. random_euler_angles = test_helpers.generate_random_test_euler_angles() with self.subTest(name=("is_normalized")): random_axis, random_angle = axis_angle.from_euler(random_euler_angles) pred = axis_angle.is_normalized(random_axis, random_angle) self.assertAllEqual(np.ones(shape=random_angle.shape, dtype=bool), pred) with self.subTest(name=("is_not_normalized")): random_axis *= 1.01 pred = axis_angle.is_normalized(random_axis, random_angle) self.assertAllEqual(np.zeros(shape=random_angle.shape, dtype=bool), pred)
def generate_preset_test_axis_angle(): """Generates pre-set test rotation matrices.""" angles = generate_preset_test_euler_angles() axis, angle = axis_angle.from_euler(angles) return axis, angle