What determines the direction of an object that has undergone the effect of a gravitational slingshot?

I just started researching this topic and therefore I do not know much about it. Nonetheless, I am still curious about what determines the direction an object takes after passing by a planet. I think the new direction is most likely determined by the gravity of set planet and the new direction can be calculated using vectors. But I also think that the speed of the planet can have an influence in the new direction of the object. In both cases I believe that the new direction is found by adding vectors or by using Pythagora's. Can someone correct me?

• The planet's speed definitely has an effect, but you can't get an answer just by "adding vectors". You simply have to integrate $F=ma$ while there's a non-negligible force, calculating the rocket's new speed and position at each instant, using $F=GmM/r^2$, $F$ the force acting on the rocket, $m$ its mass, $M$ the Earth's mass, and $r$ the distance between them. That can easily (even trivially) be done numerically, but I'm not sure whether or not there's a closed-form solution, especially since the total $F$ on the rocket would have to include the always-non-negligible Sun in addition to Earth. – John Forkosh Jan 11 at 20:30
• @JohnForkosh I think there is a closed form if we assume the flyby happens fast enough that the no other bodies exert a meaningful impulse to the spacecraft during it. I don't have time to post an answer right now though. – jacob1729 Jan 11 at 20:36
• Actually, in retrospect, I think there probably is a closed-form solution, but definitely not by simply adding vectors. It's a gravitational three-body problem, which has no general closed-form solution. But in this case, two of the bodies are essentially infinitely massive (and hence negligibly affected) with respect to the third. And I believe there's a closed-form solution for that special case (among various other special cases). – John Forkosh Jan 11 at 20:38