What's new

C/C++ N-Body Simulation

Liquid44

Liquid44

Banned
Programmer
Messages
1,158
Reaction score
691
Points
245
Sin$
0
I am releasing a command line application I made a while ago and thought some people might find it interesting.

This is an n-body simulation under gravitational attraction, which means all particles affect every other particle. This can get very computationally expensive due to O(n^2) time complexity (I might optimise it in the future but not now) so that's why I have kept the number of particles fixed at 4096.

The arguments are:

-d = delta time which controls are quickly particles advance every frame
-s = number of frames you want to simulate
-r = number of frames you want to render out

The frames are rendered out as .tga images in the same directory as the executable.
Here is a screenshot of the application running.

Screenshot.png





Top left shows the program running and right side shows the rendered output image.

The effect produced when you put the images in a sequence is quite cool and forms little clusters that occasionally explode because the force between the particles is inversely proportional to the square of the distance between them.

Virus Scans:
https://www.virustotal.com/en/file/1...is/1371593810/
http://vscan.novirusthanks.org/analysis/6cea83611136036adb868e2753a57dd6/Z3Jhdml0eQ==/

Download:
Download gravity from Sendspace.com - send big files the easy way

Notes:

Compiled under ubuntu 11.04 so this is a linux executable, windows users will have to dual boot or run a virtual machine to use this.

A good value to use for delta time is around 10000.

When I ran the program on my laptop, each frame takes like a minute to render.

I implemented basic error checks so if you enter invalid arguments then it will display example usage.

Written in c++ with no external libraries, I enjoy doing physics simulations so if you have ideas for improvement let me know.
 
Fire30

Fire30

Seasoned Member
Messages
7,222
Reaction score
2,364
Points
635
Sin$
0
This is really cool. Is the source available, because I would really like to see how this is made?
 
Liquid44

Liquid44

Banned
Programmer
Messages
1,158
Reaction score
691
Points
245
Sin$
0
This is really cool. Is the source available, because I would really like to see how this is made?


Thanks and sorry I don't wanna release the full source, however if there are specific parts you are interested in then I can post various snippets of code and give an explanation.
 
Top Bottom
Login
Register