predicting projectile interception

I'm trying to write code to predict when a player can intercept a projectile. In the case where the projectile has a slower velocity than the player, but passes the closest point of approach before the player can reach it, I'm a little stumped. I've "reduced" the problem down to some kind of summation, where I can loop until a tolerance is reached, but I'd like a more direct way to calculate based off of the projectile speed, player speed, and relative positioning, how much time passes or how much ground the projectile covers before the player overtakes it.

Code:
old version
[deleted]
A short nap answered the a == 0.0 case. Both the ball and player have the same speed, which is a special case to handle. I also notice that whenever a == 0.0, b and sqrt(discriminant) have a nearly equal absolute value.

I have also figured out that sometimes when the discriminant < 0.0, the player is already in line with the ball, or the ball is past the player and moving away from the player. I haven't yet determined how to conclusively handle discriminant < 0.0 because I am still not sure what the root cause is or even all the cases that can be handled specially that cause it to be so. I'm hoping that some more debugging will turn up another clue.
Code:
// Returns time until player can intercept linear path of ball,
//
// Inputs: ball's radius, position, velocity,
//                    time delay until it can start moving
//         player's radius, position, speed (no acceleration, assumes that
//                    player can go full speed in any direction necessary),
//                    time delay until it can start moving
//
// returning by reference the position along ball's path where player will first be able to touch it
// returning by reference the extra time player has until ball reaches that interception point
// returning the time it took for the player to reach the point where it would touch the ball at the interception point
b2Float predictBallPlayerInterception(const b2Float &ballRadius, const b2Vec2 &ballPosition, const b2Vec2 &ballVelocity, const b2Float &ballBeginMovementDelay,
                                      const b2Float &playerRadius, const b2Vec2 &playerPosition, const b2Float &playerSpeed, const b2Float &playerBeginMovementDelay,
                                      b2Vec2& interceptionPosition, b2Float &extraTime)
{
    b2Vec2 ballMovementDirection = ballVelocity;                                                            // get ball movement direction
    b2Float ballSpeed = ballMovementDirection.Normalize();                                                  // get ball speed
    b2Vec2 offsetToBall = ballPosition - playerPosition;                                                    // get player movement required to get to current ball position
    b2Float distanceFromPlayerToBallAtInterception = fabs(b2Cross(ballMovementDirection, offsetToBall));    // distance to from player center to center of ball at interception point
    b2Float distanceBallTravelsToPassPlayer = -b2Dot(ballMovementDirection, offsetToBall);                  // distance until ball passes player
    b2Float timeUntilBallPassesPlayer = ballSpeed == 0.0 ? 0.0 :                                            // interval until ball passes player
        distanceBallTravelsToPassPlayer / ballSpeed + ballBeginMovementDelay;
   
    interceptionPosition = ballPosition + distanceBallTravelsToPassPlayer * ballMovementDirection;          // calculate interception position
   
    b2Float timeUntilPlayerReachesInterception = b2Max(0.0,                                                 // discover how long it will take for the player to reach the interception point
        (distanceFromPlayerToBallAtInterception - ballRadius - playerRadius) / playerSpeed + playerBeginMovementDelay);
   
    if(timeUntilPlayerReachesInterception <= timeUntilBallPassesPlayer)                                     // if the player can get to the interception point before the ball arrives
    {
        extraTime = timeUntilBallPassesPlayer - timeUntilPlayerReachesInterception;                         // most of the time is extra
        return timeUntilPlayerReachesInterception;                                                          // and it takes no time for the player to arrive
    }
    else if(ballSpeed > playerSpeed)                                                                        // misses the chance or there is no chance to get the ball
    {
        return DBL_MAX;
    }
   
    b2Float headStartToInterceptionPoint = ballRadius + playerRadius -                                      // formula's adjustment for radii and player start delay
                                           playerSpeed * playerBeginMovementDelay;
    b2Float ballSpeedSquared = ballSpeed * ballSpeed;                                                       // convenience since it is used multiple times
   
    b2Float a = ballSpeedSquared - playerSpeed * playerSpeed;                                               // calculate coefficients of quadratic
   
    b2Float b = -2.0 * (ballSpeedSquared * timeUntilBallPassesPlayer +
                        playerSpeed * headStartToInterceptionPoint);
    b2Float c = ballSpeedSquared * timeUntilBallPassesPlayer * timeUntilBallPassesPlayer +
                distanceFromPlayerToBallAtInterception * distanceFromPlayerToBallAtInterception +
                headStartToInterceptionPoint * headStartToInterceptionPoint;
   
    b2Float discriminant = b * b - 4.0 * a * c;
    b2Assert(discriminant >= 0.0);
    b2Float sqrtDet = sqrt(discriminant);
    b2Float root1 = (-b - sqrtDet) / (2.0 * a);
    b2Float root2 = (-b + sqrtDet) / (2.0 * a);
   
    b2Float timeUntilInterception =                                                                         // choose smallest positive root, otherwise choose smallest absolute value
        (root1 >= 0.0 && root2 >= 0.0) ? b2Min(root1, root2) : b2Max(root1, root2);
   
    extraTime = timeUntilBallPassesPlayer - timeUntilInterception;                                          // player waits this long for ball to arrive at interception position
    return timeUntilInterception;                                                                           // return interval until interception occurs
}


Got it working. You can see the if and else if, which handle the special cases.

Original thread: https://box2d.org/forum/viewtopic.php?t=8833