Skip to main content

intersect_line_torus

Function intersect_line_torus 

Source
pub fn intersect_line_torus(
    torus: &ToroidalSurface,
    origin: Point3,
    dir: Vec3,
) -> Vec<f64>
Expand description

Real intersection parameters t of the line origin + t·dir with a torus.

A line meets a torus in up to four points (degree-4). Substituting the line into the torus implicit (a² + b² + c² + R² − r²)² = 4R²(a² + b²) — where (a, b, c) are the line point’s coordinates in the torus frame — gives a quartic in t, solved here for its real roots (each refined by one Newton step against the implicit). dir need not be unit length; t is in units of dir. Returns the roots sorted ascending (0–4 of them).

Used by the boolean section trimmer to find where a plane×torus oval exits a box face’s straight boundary edge — the exact crossing shared by the two adjacent faces, which is what makes the notch watertight.