Skip to main content

ray_sphere_intersect

Function ray_sphere_intersect 

Source
pub fn ray_sphere_intersect(
    origin: Vector3D,
    dir: Vector3D,
    center: Vector3D,
    radius: f64,
) -> Option<(f64, Vector3D)>
Expand description

Intersects a ray with a sphere centered at center with radius radius.

Uses the standard quadratic-form ray-sphere test. Returns Some((t, n)) where t is the nearest positive intersection distance along the ray and n is the outward unit normal at the hit point. Returns None if the ray misses.

§Arguments

  • Vector3D - The ray origin.
  • Vector3D - The ray direction (expected to be unit length).
  • Vector3D - The sphere center.
  • f64 - The sphere radius (must be positive).

§Returns

  • Option<(f64, Vector3D)> - The hit distance and surface normal, or None on miss.