A gravitational keyhole is a tiny region of space where a planet's gravity would alter the orbit of a passing asteroid such that the asteroid would collide with that planet on a given future orbital pass. The word "keyhole" contrasts the large uncertainty of trajectory calculations (between the time of the observations of the asteroid and the first encounter with the planet) with the relatively narrow bundle(s) of critical trajectories. The term was coined by P. W. Chodas in 1999. It gained some public interest when it became clear, in January 2005, that the Asteroid 99942 Apophis would miss the Earth in 2029 but may go through one or another keyhole leading to impacts in 2036 or 2037. Further research has since been done, however, which revealed the probability of Apophis passing through the keyhole was extremely insignificant.
Keyholes for the nearer or further future are named by the numbers of orbital periods of the planet and the asteroid, respectively, between the two encounters (for example “7:6 resonance keyhole”). There are even more but smaller secondary keyholes, with trajectories including a less close intermediate encounter ("bank shots"). Secondary gravitational keyholes are searched for by importance sampling: virtual asteroid trajectories (or rather their ‘initial’ values at the time of the first encounter) are sampled according to their likelihood given the observations of the asteroid. Very few of these virtual asteroids are virtual impactors.
Due to observational inaccuracies, inaccuracies in the frame of reference stars, bias in the weighting of major observatories over smaller ones, and largely unknown non-gravitational forces on the asteroid, mainly the Yarkovsky effect, its position at the predicted time of encounter is uncertain in three dimensions. Typically, the region of probable positions is formed like a hair, thin and elongated, because visual observations yield 2-dimensional positions in the sky but no distances. If the region is not too extended, less than about one percent of the orbital radius, it may be represented as a 3-dimensional uncertainty ellipsoid and the orbits (ignoring the interaction) approximated as straight lines.
Now imagine a plane comoving with the planet and perpendicular to the incoming velocity of the asteroid (unperturbed by the interaction). This target plane is named b-plane after the collision parameter b, which is the distance of a point in the plane to the planet at its coordinate origin. Depending on a trajectory's position in the b-plane its post-encounter direction and kinetic energy is affected. The orbital energy is directly related to the length of the semi-major axis and also to the orbital period. If the post-encounter orbital period of the asteroid is a fractional multiple of the orbital period of the planet, there will be a close encounter at the same orbital position after the given numbers of orbits.
According to Ernst Öpik's theory of close encounters, the set of points in the b-plane leading to a given resonance ratio forms a circle. Lying on this circle are the planet and two gravitational keyholes, which are images of the planet in the b-plane of the future encounter (or rather of the slightly larger catchment area due to gravitational focusing). The form of the keyholes is a small circle elongated and bent along the circle for the given resonance ratio. The keyhole closest to the planet is smaller than the other, because the variation of deflection becomes steeper with decreasing collision parameter b.
Relevant keyholes are those close to the uncertainty ellipsoid projected onto the b-plane, where it becomes an elongated ellipse. The ellipse shrinks and jitters as new observations of the asteroid are added to the evaluation. If the probable path of the asteroid keeps close to a keyhole, the precise position of the keyhole itself would matter. It varies with the incoming direction and velocity of the asteroid and with the non-gravitational forces acting on it between the two encounters. Thus, “a miss is as good as a mile” does not apply to a keyhole of several hundred meters width. However, changing the path of an asteroid by a mile can be done with a relatively small impulse if the first encounter is still years away. Deflecting the asteroid after the fly-by would need a much stronger impulse.
For a rapidly rotating planet such as the Earth, calculation of trajectories passing close to it, less than a dozen radii, should include the oblateness of the planet—its gravitational field is not spherically symmetric. For even closer trajectories, gravity anomalies may be important.
For a large asteroid (or comet) passing close to the Roche limit, its size, which is inferred from its magnitude, affects not only the Roche limit but also the trajectory because the center of gravitational force on the body deviates from its center of mass resulting in a higher-order tidal force shifting the keyhole.