Simple Gravity Simulation

This project is my first experiment with Qt. Usually I like to keep things simple and without gui. But sometimes it is really helpful if you are able to draw stuff - like in this simple gravity simulation. It reads in a csv file with initial information (position, velocity and mass) of objects. With the help of a timer, it periodically calculates the influence of the objects on each other and updates their positions and velocities. The simulation can be paused and resumed using the space key on the keyboard.

As you might have already noticed in the gif above, there is no collision detection. Two objects which get close to each other fly out of the viewing area really fast (the resulting force is inverse proportional to the distance so if the distance gets small, the force gets really strong).

However you can still see some quite interesting things with it. There are some example configurations included in the package below. The file three_obj_2.csv for example contains a constellation of a star with one planet that has a moon. You can see the planet orbiting the star and the moon orbiting the planet.

To generate an executable binary out of the sources, just run the build.sh script in the root folder after unpacking the files (you might need to install Qt5 first). There is also a script to run the binary called run.sh.

Files:

Back to home.