def test_rotate_random(self): """Tests that the rotate provide the same results as quaternion.rotate.""" random_axis, random_angle = test_helpers.generate_random_test_axis_angle() tensor_shape = random_angle.shape[:-1] random_point = np.random.normal(size=tensor_shape + (3,)) random_quaternion = quaternion.from_axis_angle(random_axis, random_angle) ground_truth = quaternion.rotate(random_point, random_quaternion) prediction = axis_angle.rotate(random_point, random_axis, random_angle) self.assertAllClose(ground_truth, prediction, rtol=1e-6)
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_rotate_jacobian_random(self): """Test the Jacobian of the rotate function.""" x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle( ) x_axis = tf.convert_to_tensor(value=x_axis_init) x_angle = tf.convert_to_tensor(value=x_angle_init) x_point_init = np.random.uniform(size=x_axis.shape) x_point = tf.convert_to_tensor(value=x_point_init) y = axis_angle.rotate(x_point, x_axis, x_angle) self.assert_jacobian_is_correct(x_axis, x_axis_init, y) self.assert_jacobian_is_correct(x_angle, x_angle_init, y) self.assert_jacobian_is_correct(x_point, x_point_init, y)