Fly-by of a planet

or what concerns the solar system, the Sun can be considered as the main attractor, being much more massive than the other bodies. The orbit of any body can therefore be calculated, in a first, very approximated determination, considering the only gravitational attraction of the Sun. The main exception to this approximated law takes place when the body (which can be an asteroid or a comet) comes near a planet. In this case, there is a zone where the attraction of the planet is much stronger than the attraction of the other bodies (including the Sun). This zone is called the sphere of influence of the planet and inside it, the original orbit of the body is drastically changed by the action of the planet.
This phenomena is one of the most efficient in pulling asteroids from their stable orbits into highly unpredictable ones, becoming NEOs.

Sphere of influence

How is the sphere of influence of a planet defined? Intuitively, the bigger planets (such as Earth and Venus) must have a bigger influence on minor bodies than the smaller ones, like Mercury or Mars. The dimension of the sphere of influence, defined as the region where the attraction of the planet is predominant compared to the attraction of the other bodies, is in fact proportional to the mass of the planet.
When a body enters this region, its new orbit can be determined considering only the gravitational attraction of the planet and neglecting any other gravitational force that acts on it. In this case, its orbit can be approximated with an hyperbole (as it is shown in the picture).

What happens when a minor body comes inside the sphere of influence of a planet?

When a minor body comes very near to a planet, its orbit changes abruptly becoming unstable. In a first approximation, this new orbit is independent from the original, old trajectory, but it is very sensible to the initial conditions of the actual motion (the conditions of the body just before it enters the sphere).
In fact, when the asteroid passes near a planet, the new orbit will depend strongly on how close the NEO passes from the planet, on its speed, on its exact position, etc. In other words, the new orbits are highly divergent and a minimum difference in the initial conditions will lead to completely different final orbits, after the fly-by of the planet. For this reason this mechanism can be seen as an amplificator of chaos.
In the image on the right, the orbits that cross the sphere of influence are divergent (in white) while the others are not (the blue orbits).