The celestial mechanics of gravity assist