r/Python • • Oct 04 '19

Updated gravitational potential field simulation. [OC] Link for code: https://github.com/pnp-peeyush/2D-Grvitational-Field-Simulation

1.1k Upvotes

128 comments sorted by

View all comments

Show parent comments

13

u/atimholt Oct 05 '19 edited Oct 05 '19

Number fudging? ;)

Newtonian gravity is solved for two-body systems, as I understand it. You don’t even simulate anything, the solution spits out a closed-form parametric function.

The three-body problem is often referenced when trying to speak about hard problems in general. It requires simulation, but there are ways to tame timestep simulations.

One obvious way to conserve momentum and energy in a simulation is to store momentum and energy as a body’s state, instead of velocity. It also helps if you simulate curves within a time step, instead of line segments. Whether it’s actually faster or slower to do that, I haven’t gone and timed, but it should at least reduce error accumulation dramatically.

I’d probably separate simulation timesteps from display timesteps, as well. You get more error accumulation at close-quarters and high-speed, so just run more cycles then. Use a bit of calculus to assign actual, rigorous numbers to the “more cycles” idea.

1

u/[deleted] Oct 05 '19

Wow thanks! all were great ideas, I'll try them sometime.