Comets are like small planets that follow orbits of all shapes and sizes around the Sun. Usually, these orbits are chaotic and highly elongated — taking the comets far from our star at their farthest points — and they can change significantly due to the gravitational influences of the major planets. To determine a comet’s orbit, we start by observing its positions with respect to the cataloged locations of background stars, and then apply the laws of physics.
Astronomy magazine subscribers can read the full answer for free. Just make sure you're registered with the website.