Note: This is an older post and the gravity simulation code has since been updated. See here for the latest.

I recently revisited the 3D Gravity simulation code in Visions Of Chaos. Adding a few new features really helped improve the resulting outcomes.

First is changing to 2nd order Euler integration. This gives a much more accurate result in the force between objects calculations. Using 4th order Runge-Kutta would be the ideal and is planned for the future.

Second is adding a setting for minimum distance that objects interact. If you use the default Newtonian gravity formulas for 2 objects and they are too close to each other then this will usually lead to one or both of the objects being flung off out of the simulation area at an enormous speed. Even though this is the correct accurate result it generally leads to all objects being flung out of the screen within the first hundred steps or so. Including a minimal distance means that force calculations between any objects closer than a small value are ignored. A good factor seems to be around 1% or so of the world size.

Third was adding trails tracing to the particles. After implementing this with the Boids code it was simple enough to use it with the 3D Gravity too.

Here is a movie showing the new results. First part is a circular cloud of particles and the second part is a top down disc of rotating objects.

Jason.

2 responses to “3D Gravity Updates”

1. This is great stuff!

I have some simple questions:
1. Do you in some way overcome the N^2-scaling of the force calculations?

2. Wouldn’t a symplectic integrator (such as synplectic Euler or Størmer-Verlet) be a much better choice than standard RK4? RK methods have unfortunate damping effects (exact solutions that are closed loops become spirals), while synplectic methods behave much better for Hamiltonian systems.

Without being an expert in gravitating body-simulations, I would assume that the state-of-the-art scientific codes used symplectic methods in addition to sophisticated averaging techniques to overcome the N^2-scaling ..

Best,
Simen.

2. softologyblog says:

At this stage I am doing bruit force calculations between all objects. Barnes-Hutt is planned for a future release.

I hadn’t heard of the symplectic methods before. I will look into them. Thanks.

Jason.