How the function calculates line-sphere intersections
Intersection of a Line and a Sphere is a MAXScript function for finding where a line meets a sphere. Royal Ghost's function adapts the method described by Paul Bourke. Given two points, P1 and P2, on a line and a sphere with center P3 and radius r, the method substitutes the parametric line P(u) = P1 + u(P2 - P1) into the sphere equation. The result is a quadratic in u. Its discriminant, D = b² - 4ac, classifies the intersection: D below zero means no hit, D equal to zero means a tangent, and D above zero means two intersections.
How the quadratic is formed
Using the dot product, the coefficients are a = (P2 - P1) · (P2 - P1), b = 2(P2 - P1) · (P1 - P3), and c = (P1 - P3) · (P1 - P3) - r². When D is zero or positive, the parameter values are u = (-b ± sqrt(D)) / (2a). Substituting each root into P(u) gives the corresponding point on the line. The parameter values also show whether those points fall within a bounded part of the line.
Reading results for a segment
The equation describes an infinite line. For a segment from P1 to P2, keep roots in the inclusive range 0 ≤ u ≤ 1. Two distinct roots in that range mean the segment crosses the sphere twice; a repeated root in range is a tangent, and one root in range with the other outside it means a single crossing. If neither root is in range, the infinite line may still intersect the sphere beyond an endpoint. When one root is below zero and the other above one, the segment lies inside the sphere without crossing its surface. When both roots lie on the same side of the range, the segment is outside the sphere.
Using it in a MAXScript workflow
This function suits scripts that need line and sphere intersection parameters before carrying out later scene operations. The parameter test can distinguish a full-line intersection from a hit on a particular segment. The retrieved listing identifies it as a function port but does not show its call signature or return format, so check the script and its readme for those integration details.
Source and version
ScriptSpot's listing credits Royal Ghost and gives version 1.0.0. It describes the function as a MAXScript version of Paul Bourke's line and sphere method; Bourke's write-up gives the segment parameter cases.




