private bool Intersects(IBoundingSphere bs) { if (!bs.Valid()) { return(true); } var startToCenter = Start - bs.Center; double c = startToCenter.LengthSquared() - System.Math.Pow(bs.Radius, 2); if (c < 0.0) { return(true); } var startToEnd = End - Start; double a = startToEnd.LengthSquared(); double b = Vector3.Dot(startToCenter, startToEnd) * 2.0; double d = b * b - 4.0 * a * c; if (d < 0.0) { return(false); } d = System.Math.Sqrt(d); double div = 1.0 / (2.0 * a); double r1 = (-b - d) * div; double r2 = (-b + d) * div; if (r1 <= 0.0 && r2 <= 0.0) { return(false); } if (r1 >= 1.0 && r2 >= 1.0) { return(false); } if (IntersectionLimit == IntersectionLimitModes.LimitNearest && 0 != Intersections.Count()) { if (startToCenter.Length() > Intersections.First().StartToIntersectionDist) { return(false); } //double ratio = (startToCenter.Length() - bs.Radius) / System.Math.Sqrt(a); //if (ratio >= Intersections.First().Ratio) return false; } // passed all the rejection tests so line must intersect bounding sphere, return true. return(true); }