///<summary>Returns the first non-negative time, if any, where a moving circle will intersect a fixed extended line.</summary> public static double? WhenMovingCircleWillIntersectExtendedLine(Point center, double radius, Vector velocity, Point pointOnLine, Vector displacementAlongLine) { var a = (center - pointOnLine).PerpOnto(displacementAlongLine); if (a * a - radius * radius <= 0) return 0; // already touching at t=0? var b = velocity.PerpOnto(displacementAlongLine); var kissTime = QuadraticRoots(b * b, a * b * 2, a * a - radius * radius) .Where(e => e >= 0) .Cast<double?>() .FirstOrDefault(); return kissTime; }