# How do spacecraft gain kinetic energy by passing near planets? [duplicate]

When a a spacecraft like Voyager travels close to Jupiter, it somehow gains kinetic energy. I'm not sure how this energy isn't simply lost again as it moves away from Jupiter. I'm also hoping this will explain how stars can be ejected from galaxies!

Here's a simple example to illustrate. Suppose that we have a spacecraft doing an encounter with a planet. In the reference frame moving with the planet, let's suppose that the spacecraft has an initial velocity of $\vec{v}_{ip} = v \hat{y}$ and a final velocity of $\vec{v}_{fp} = v \hat{x}$. In other words, the spacecraft follows a hyperbola whose asymptotes make a 90° angle. By conservation of energy, and to the extent that we can view the planet as fixed (which is a very very good approximation here), the magnitudes of the initial and final vectors will be equal, and so will the initial and final kinetic energies.
But now look at this in the frame of the Sun. Specifically, let's suppose that the planet is moving at a speed $\vec{V} = v \hat{x}$ relative to the sun. The spacecraft's initial velocity relative to the Sun will be $\vec{v}_{is} = \vec{v}_{ip} + \vec{V} = v (\hat{x} + \hat{y})$; the final velocity will be $\vec{v}_{fs} = \vec{v}_{fp} + \vec{V} = 2 v \hat{x}$. Because we have sneakily aligned the spacecraft's departure direction with the planet's motion, the spacecraft ends up moving a good deal faster relative to the sun after the encounter (twice as much kinetic energy, in this case.)