Skip to content

Instantly share code, notes, and snippets.

@SalvatorePreviti
SalvatorePreviti / gist:0ec6a73cb14cd33f12350ae27468f2e7
Last active May 20, 2024 02:00
GetFrustumLineIntersection - find the intersection of an infinite line with a view frustum in Unity (improved, with tolerance, stable on corner cases)
/// <summary>
/// Computes the intersection points between a frustum and an infinite line.
/// Finds the visible part of a segment in respect of a camera frustum.
/// Returns false if the line is not visible at all.
/// </summary>
/// <example>
/// var planes = GeometryUtility.CalculateFrustumPlanes(camera);
/// if (GetFrustumLineIntersection(camera, planes, ray, out d1, out d2)) {
/// Gizmos.DrawLine(ray.GetPoint(d1), ray.GetPoint(d2));
/// }