# small gravity simulation problem.

This topic is 4521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello. I'm working on a 3d gravity simulation thing. It works for the most part, but sometimes a particle will pass through another particle, and shoot it away with incredible speed... I know the reason, and I'll try to explain. gravity has an inverse square relation with distance. 1 particle happens to be moving very near another particle.. Frame by frame.. 1st frame, the particles are close together, they accelerate towards each other as expected. 2nd frame, the particles happen to be EXTREMELY close together, and there is a huge force. 3rd frame, the particle is already far away, far enough that the gravity will not slow it down like it should. When I have about 30 particles on the screen at the same time, this occurs once every ten seconds or so. I have one or two ideas, but I'd like to hear your suggestions if you have any. I'll let you know if I've come up with anything that works, myself. Thanks for your help.. Adam

##### Share on other sites
this kind of stuff typically happens because you're not integrating very well. decrease your timestep, use a different technique, etc.
edit: by the way, you should definitely prevent the particles from getting too close to each other.

##### Share on other sites
You could just set a small radius of non-gravitation for each particle.

i.e. if dist(p1,p2) < EPS then do nothing...

##### Share on other sites
A commonly-used solution is to soften the distance calculation. That is, add a small constant to the interparticle distance (or its square) when calculating interparticle forces. When interparticle distances are large, the small constant has negligible effect on the results. When the interparticle distance is very small, the constant acts as a minimum value, and thus a maximum cap on what the force / acceleration on the aprticles can be, preventing huge single-frame forces that throw particles completely out of the simulation.

This does introduce some problems though... In particular, instead of a nice consistent elliptical orbit, you'll probably get a noticably precessing orbit.

Also, as suggested above, using a better (higher order) integration scheme might help, or reducing the current scheme's step size, or using a variable-step-size scheme that uses smaller step sizes whenever the acceleration gets too big.

Alternatively, if you only have two-particle close interactions, you could perhaps switch to a time-parameterization of Keplerian orbits whenever two particles get close enough to break the numerical integrator. I believe time-parameterizing such orbits is rather complicated though... possibly requiring elliptical integrals (yay buzzword)...

##### Share on other sites
If your particles have no size and there is nothing preventing two particles from occupying the same space, then your your particles are effectively black holes.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633287
• Total Posts
3011217
• ### Who's Online (See full list)

There are no registered users currently online

×