No description
Find a file
2026-07-27 21:26:45 -07:00
media change n_body sim to use numpy struct, and organizational changes 2026-07-27 21:25:32 -07:00
n_body destroyed everything, TODO: fix n_body class implementation (rk) 2026-05-11 00:01:44 -07:00
old change n_body sim to use numpy struct, and organizational changes 2026-07-27 21:25:32 -07:00
.gitignore updated README.md, and uploaded some plots 2026-05-21 04:04:00 -07:00
body.py energy conservation complete (mostly - collision wip) 2026-05-18 01:25:57 -07:00
damp_osc_with_rk_single.py created three body.py 2026-04-15 21:15:11 -07:00
draw.py Fixed panda3d cannot invert Lmatrix4 error, and updated README.md 2026-05-21 05:12:56 -07:00
gravity_sim.py change draw api to start and end frame; implement axes 2026-04-14 20:53:06 -07:00
n_body_gravity.py change n_body sim to use numpy struct, and organizational changes 2026-07-27 21:25:32 -07:00
new_energy_n_body.py change n_body sim to use numpy struct, and organizational changes 2026-07-27 21:25:32 -07:00
one_body.py n_body.py works for 3 bodies. Still need to implement collision (when r=0, it currently results in NaN). Also need to add functions to support moving CM, changing mass overtime, and energy support (to make it accurate to real life). 2026-04-17 06:52:32 -07:00
README.md update README.md 2026-07-27 21:26:45 -07:00
rk.py n_body.py works for 3 bodies. Still need to implement collision (when r=0, it currently results in NaN). Also need to add functions to support moving CM, changing mass overtime, and energy support (to make it accurate to real life). 2026-04-17 06:52:32 -07:00
spring.py added semi-correct implementation of rk in rk.py 2026-04-12 20:51:24 -07:00
test.py energy conservation complete (mostly - collision wip) 2026-05-18 01:25:57 -07:00
test_particle_sim.py change n_body sim to use numpy struct, and organizational changes 2026-07-27 21:25:32 -07:00

Setup

pip install numpy pyglet matplotlib panda3d

matplotlib is not necessary if not plotting

Note:

new_energy_n_body.py and n_body.py are the only ones that will currently run due to changes made to rendering. Other files haven't been updated with the new syntax yet.

To-do

  • Gravity on Earth
  • Build a 2d renderer based on Pyglet
    • Implement multi-object rendering
    • Reuse old shapes
  • Implement inelastic collision models
    • Come up with different models for bodies colliding
    • Supoort for different types of collisions (and respective energy+momentum changes)
  • Build a 3d renderer based on Panda3D
  • Switch to Barnes-Hut method for approximations for particles
  • Springs
  • Diff eq. support
  • Two-body problems
    • One fixed body
  • N-body problems
    • basic N-body problems
    • implement fast multipole method
    • parallelization
    • energy conservation
  • Particle simulation
    • similar to N-body sims, with perfectly elastic collisions
  • Fluid simulation

Switched from RK4 to velocity verlet for significant performance gains, and energy+momentum conservation.

Example System

Energy and momentum graphs for an 27 body gravitational system with velocity verlet (time step = 0.05): Total energy = -24902.30544431605; Total energy final (1000 seconds) = -24902.30544250108

Note: Not sure what the spikes are. They are likely due to improper "collision" handling (there is no collision handling, instead 0 acceleration is added if the delta position is less than sum of radii, where the radii have a minimum radius of 1, despite "true" raidus being proportional to cbrt of mass, which would give sub pixel radii)

Zoomed in energy plot

<p_x, p_y, p_z> represent each of the 3 lines. Total momentum = <687898.600061, 198487.305684, 0>; Total momentum final (1000 seconds) = <-733713.21844474, 3488328.45607243, 0.>