r/Python • • Jan 14 '20

I made a gravity simulation https://github.com/phgilde/gravity_simulation

1.8k Upvotes

82 comments sorted by

View all comments

1

u/homelesspancake Jan 15 '20

How does a gravity simulation work? Like, what’s the math there?

8

u/[deleted] Jan 15 '20

For every particle, you calculate the vector sum of the gravitational Forces to every other particle. That is your acceleration in the next time step. Add this acceleration to the particles current speed and move the particle by this speed.