Physics / Astronomy
Galaxy (Barnes-Hut N-body)
A spiral galaxy star by star: gravity alone winds up the arms.

What happens
Tens of thousands of stars, each pulled by all the others. The disk starts cold and rotating; its own gravitational instabilities wind up into spiral arms - nobody draws them. Switch to the merger to watch two galaxies tear tidal tails off each other. The Barnes-Hut tree makes it real-time: distant groups of stars act as single point masses.
Equations used in the module
Equations a_i = G Σ M_j (r_j − r_i)/(d² + ε²)^(3/2) Φ_i = −G Σ M_j/√(d² + ε²) s/d < θ; θ = 0.6 v(t+h/2) = v(t−h/2) + ah; r(t+h) = r(t) + hv(t+h/2) halo: Φ_h = −G M_h/(r + a_h), a_h = R ; v_c² = G (M_b + M_d (r/R)²)/r + G M_h r/(r + a_h)² pair: v = √(2μ/D), v_t = √(2μp)/D ; n = (sin i cos ω, cos i, sin i sin ω)


