No description
Find a file
2026-06-01 01:06:57 -07:00
n_body destroyed everything, TODO: fix n_body class implementation (rk) 2026-05-11 00:01:44 -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.py added one body simulation in one_body.py 2026-04-14 18:49:56 -07:00
damp_osc_with_rk_single.py created three body.py 2026-04-15 21:15:11 -07:00
dampened_oscillator.png updated README.md, and uploaded some plots 2026-05-21 04:04:00 -07:00
draw.py Fixed panda3d cannot invert Lmatrix4 error, and updated README.md 2026-05-21 05:12:56 -07:00
draw_old.py temp 3d renderer 2026-05-19 19:44:05 -07:00
energy.png updated README.md, and uploaded some plots 2026-05-21 04:04:00 -07:00
energy_n_body.py temp 3d renderer 2026-05-19 19:44:05 -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.py switched to velocity verlet instead of RK. Energy and momentum conserveation achieved. Need to fix :linmath(warning): Tried to invert singular LMatrix error when running solarsystem model. 2026-05-20 01:37:03 -07:00
new_energy_n_body.py add sample particle sim 2026-06-01 00:53:53 -07:00
one_body.png updated README.md, and uploaded some plots 2026-05-21 04:04:00 -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 push new README with optimization todos 2026-06-01 01:06:57 -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 add sample particle sim 2026-06-01 00:53:53 -07:00
velocity_verlet_11_body_energy.png updated README.md, and uploaded some plots 2026-05-21 04:04:00 -07:00
velocity_verlet_11_body_energy_zoomed.png updated README.md, and uploaded some plots 2026-05-21 04:04:00 -07:00
velocity_verlet_11_body_momentum.png updated README.md, and uploaded some plots 2026-05-21 04:04:00 -07:00
velocity_verlet_27_body_energy.png updated READNE.md, and added new plots 2026-05-21 15:06:10 -07:00
velocity_verlet_27_body_energy_zoomed.png updated READNE.md, and added new plots 2026-05-21 15:06:10 -07:00
velocity_verlet_27_body_momentum.png updated READNE.md, and added new plots 2026-05-21 15:06:10 -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 collisions
    • 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
    • add functions to support moving center of mass
    • add functions to model changing mass overtime
    • energy support (to make it accurate to real life)
  • Particle simulation
  • 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.>