intersectsWithSphere method
Return the distance from the origin of this to the intersection with
other
if this intersects with other
, or null if the don't intersect.
Implementation
double intersectsWithSphere(Sphere other) {
final double r = other._radius;
final double r2 = r * r;
final Vector3 l = other._center.clone()..sub(_origin);
final double s = l.dot(_direction);
final double l2 = l.dot(l);
if (s < 0 && l2 > r2) {
return null;
}
final double m2 = l2 - s * s;
if (m2 > r2) {
return null;
}
final double q = math.sqrt(r2 - m2);
return (l2 > r2) ? s - q : s + q;
}