def test_intersection_ray_sphere_exception_raised(self): """Tests that exceptions are properly raised.""" sphere_center = np.random.uniform(size=(3, )) point_on_ray = np.random.uniform(size=(3, )) sample_ray = np.random.uniform(size=(3, )) normalized_sample_ray = sample_ray / np.linalg.norm(sample_ray, axis=-1) positive_sphere_radius = np.random.uniform(sys.float_info.epsilon, 1.0, size=(1, )) negative_sphere_radius = np.random.uniform(-1.0, 0.0, size=(1, )) with self.subTest(name="positive_radius"): with self.assertRaises(tf.errors.InvalidArgumentError): self.evaluate( ray.intersection_ray_sphere(sphere_center, negative_sphere_radius, normalized_sample_ray, point_on_ray)) with self.subTest(name="normalized_ray"): with self.assertRaises(tf.errors.InvalidArgumentError): self.evaluate( ray.intersection_ray_sphere(sphere_center, positive_sphere_radius, sample_ray, point_on_ray))
def test_intersection_ray_sphere_jacobian_random(self): """Test the Jacobian of the intersection_ray_sphere function.""" tensor_size = np.random.randint(3) tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist() sphere_center_init = np.random.uniform(0.0, 1.0, size=(3, )) sphere_radius_init = np.random.uniform(10.0, 11.0, size=(1, )) ray_init = np.random.uniform(size=tensor_shape + [3]) ray_init /= np.linalg.norm(ray_init, axis=-1, keepdims=True) point_on_ray_init = np.random.uniform(0.0, 1.0, size=tensor_shape + [3]) sphere_center = tf.convert_to_tensor(value=sphere_center_init) sphere_radius = tf.convert_to_tensor(value=sphere_radius_init) ray_tensor = tf.convert_to_tensor(value=ray_init) point_on_ray = tf.convert_to_tensor(value=point_on_ray_init) y_p, y_n = ray.intersection_ray_sphere(sphere_center, sphere_radius, ray_tensor, point_on_ray) self.assert_jacobian_is_correct(ray_tensor, ray_init, y_p) self.assert_jacobian_is_correct(ray_tensor, ray_init, y_n) self.assert_jacobian_is_correct(sphere_radius, sphere_radius_init, y_p) self.assert_jacobian_is_correct(sphere_radius, sphere_radius_init, y_n) self.assert_jacobian_is_correct(sphere_center, sphere_center_init, y_p) self.assert_jacobian_is_correct(sphere_center, sphere_center_init, y_n) self.assert_jacobian_is_correct(point_on_ray, point_on_ray_init, y_p) self.assert_jacobian_is_correct(point_on_ray, point_on_ray_init, y_n)
def intersection_ray_sphere_normal(sphere_center, sphere_radius, input_ray, point_on_ray): _, y_n = ray.intersection_ray_sphere(sphere_center, sphere_radius, input_ray, point_on_ray) return y_n
def intersection_ray_sphere_position(sphere_center, sphere_radius, input_ray, point_on_ray): y_p, _ = ray.intersection_ray_sphere(sphere_center, sphere_radius, input_ray, point_on_ray) return y_p