# How to choose the parameters for a collision free comet trajectory

I implemented a simple simulation of a comet flying through space being deflected by the gravity of randomly generated planets for art purposes. My problem with that simulation is, that there are many "boring" simulations in which the comet instantly collides with a planet or is deflected to leave the viewport without an interesting trajectory.

Is there an efficient way to compute the initial values (gravitiy of the planets and initial velocity of the comet) for a simulation, in which the comet does not collide (early) with planets and possibly has an interesting trajectory (being deflected more often, slingshots, etc.)?

As I want to use it for art, there is no problem if the algorithm has constraints like only working for integer valued planet gravity or similar restrictions.

My current approach is using brute-force by simulating sets of parameters until I get an acceptable trajectory, which is rather slow.

Things I probably need (please comment to suggest others):

• Points the comet should not cross (i.e planets)
• Points with a specified velocity (e.g. near planets to deflect the trajectory from a collision course)
• Maybe way points to guide the trajectory

The parameters should not be arbitrary (the comet does not have a motor), but boundary conditions for choosing planet gravity and the initial velocity of the comet. If it's useful, the comet's mass can be chosen as well. Currently I assume the comet to be massless, which probably approximates the reality quite good.

• Have you considered using an analytic solution to get your parameters? – nicoguaro Feb 1 '19 at 0:48
• Yes, but I have no idea where to start and if it involves slow operations like solving large equation systems. I currently move the comet along the vector field calculated using the midpoint method, so I have in theory no grid. On the other hand, as I just need the visualization I could use the image pixels as grid if this allows for an efficient solution. – allo Feb 1 '19 at 7:45
• You can pick any classical mechanics book and check the two-bodies problem. – nicoguaro Feb 2 '19 at 17:43
• @nicoguaro I already thought so, but I hoped there may be some more advanced literature or some approximately solution to the problem. It should be more than two bodies, but it does not have to generalize to arbitrary n. Something between 5 to 10 or 15 bodies plus the comet (which could be assumed to have negligible mass) would be enough for a nice animation. – allo Feb 3 '19 at 9:47
• Can you explain what you mean by "collision"? Because in reality, the likelihood of anything in space colliding with anything else is vanishingly small. Or do you use oversized planets and comets so they look visually nicer? – Wolfgang Bangerth Feb 5 '19 at 13:51

You're trying to solve the n-body problem, which has some known approximations that can be used to accelerate computation; however, it's still unclear how you can turn these into artistically interesting orbits.

Some thoughts:

Place the comet near the edge of one of your planet's hill spheres with a velocity just slightly above the planet's escape velocity and, possibly, near, but under, your solar system's escape velocity. This will give you a comet with a relatively stable orbit capable of traversing, and being perturbed by, most of the system.

Alternatively, you could set up an Hohmann transfer orbit between two planets in your system, but perturb the velocity so that your comet "misses" the intended orbit.

For more complex patterns, you could figure out how to use the General Mission Analysis Tool to multi-planet assists. You could also look into the Interplanetary Transport Network.

• Thank you for the ideas and links, I will try what kinds of trajectories I can achieve. My current "interesting orbits" just consist of filtering for animations which have no collisions for x seconds, so that's not hard to beat. – allo Feb 3 '19 at 10:27
• This is a great answer -- the only thing I'd add is to make sure you're using a symplectic integrator. Naive methods often make the bodies collide or fly apart over long times even when the true orbit is closed or quasi-periodic, a problem that symplectic integrators usually avoid. – Daniel Shapero Feb 3 '19 at 19:19
• @Daniel: True. Though, from an artistic perspective such as OP mentions, using a low precision integrator might actually be preferable. – Richard Feb 4 '19 at 1:21