Simutory Galaxy Collision — physics model: equations and checks

Model identifier: extended-restricted-v3 · written 2026-10-13. This document explains the equations the simulation uses and how they were checked. You can hand it as it is to an expert or an AI when asking for a review of the model.

1. Purpose and scope of accuracy

An educational model for watching 1–4 galaxies and up to 32,000 representative stars interact in a browser on an ordinary personal computer. It is aimed at middle- and high-school students with a strong interest in science. By changing mass, amount of dark matter, approach speed, direction, spin and size, students compare tidal distortion, tails, rings, orbital decay and flybys. It is not a research simulator for predicting the future of observed galaxies or merger times quantitatively.

The method is extended restricted N-body. Each galaxy moves with the gravitational field of three components of fixed shape (dark matter halo, stellar disk and bulge). The stars shown are massless tracer particles moving in those fields. This must be distinguished from a full N-body method in which stars attract each other.

There is no merger rule that snaps centers together or overwrites velocities when galaxies come close. Centers and stars are integrated to the end. Two centers that appear to overlap do not mean that the equilibrium of a real merger remnant (a new elliptical galaxy) has been computed.

2. Forces applied and effects left out

Item How it is applied Caveats
Dark matter halo NFW profile truncated at r200. Mass from the stellar-mass–halo-mass relation (Moster 2013), concentration from Dutton & Macciò 2014 Fixed shape. Tidal stripping removes only outer mass; mass received is added with the same shape
Stellar disk Miyamoto–Nagai potential. Orientation fixed by disk tilt and direction The disk’s response of tilting or warping (torques) is not computed
Bulge and elliptical galaxies Hernquist profile Spherical, isotropic approximation
Force on stars Sum of the gravity of all three components of every galaxy Stars do not act back on the fields
Force between galaxy centers Each galaxy’s field is softened by the other galaxy’s stellar half-mass radius, then symmetrized Not the exact interaction integral of two extended distributions. As the gradient of a pair potential it conserves momentum and energy
Dynamical friction Chandrasekhar formula, mass-weighted in both directions, calibration factor κ = 0.5 (BK08) Approximates the gravitational response of the surrounding matter. It is not air drag
Tidal stripping King 1962 tidal radius, proceeding over a local orbital period (Taylor & Babul 2001 form) Only the lighter galaxy is stripped; the stripped mass and momentum move to the heavier one
Tidal force Arises naturally from the difference in force on near and far stars of the same galaxy No extra force or animation makes the tails
Spiral arms and bars Density pattern of the stars at the start (kinematic arms) Self-gravity of the arms and regeneration by density waves are not included
Dust lanes About 10.8% of disk tracers are drawn as dust (moving under the same gravity) No shocks or cooling of gas and dust. On-screen absorption is limited to optical depth 0.9
Gas dynamics, star formation, supernovae, black holes, cosmic expansion Not included Running to 10 billion years does not give real long-term evolution

3. Units and the galaxies’ gravitational fields

  • Distance kpc, time Myr, mass 10^11 M☉, G = 0.44985 kpc³/(Myr²·10^11 M☉), 1 km/s = 0.001022712 kpc/Myr.
  • In the experiment file, stellarMass is in units of 10^10 M☉ and haloMass in 10^11 M☉ (M200).
  • Cosmology: h = 0.677, ρ_crit = 3H0²/(8πG) ≈ 127 M☉/kpc³, M200 = (4π/3)·200ρ_crit·r200³. A 10¹² M☉ halo has r200 of about 211 kpc.
  • Automatic halo mass: Moster, Naab & White 2013 (z = 0) M*/M = 2N[(M/M1)^−β + (M/M1)^γ]^−1, log M1 = 11.590, N = 0.0351, β = 1.376, γ = 0.608, inverted by bisection. Because of the scene size, automatic values are capped at 4×10¹² M☉. Differences between halo mass definitions (M200c/Mvir) are at the 10–20% level.
  • Concentration: log10 c = 0.905 − 0.101 log10(M200 / 10¹² h⁻¹ M☉). rs = r200/c, μ(x) = ln(1+x) − x/(1+x).
  • Disk: for display radius R, R_d = R/3.8, MN a = 1.15 R_d, b = 0.093 a (irregular 0.3 a). The ratios follow galpy MWPotential2014 (a = 3, b = 0.28 kpc).
  • Bulge: Hernquist a_b = 0.25 R_d. Bulge share of the stellar mass: spiral 0.15, barred spiral 0.20, irregular 0, elliptical 1.0. Elliptical galaxies use a = 0.118 R (80% within R).
  • Softening: the field felt by stars is softened with ε = max(0.1, 0.25 a_b) kpc (irregular 0.1), and the gradient of Φ(s) with s = √(r²+ε²) is used as is (a conservative force).

Truncated NFW halo (normalization M_n, edge r_t):

s < r_t:  Φ = −(G M_n/μ(c)) [ln(1 + s/rs)/s − 1/(rs + r_t)],   g = G M_h(<s) r / s³
s ≥ r_t:  Φ = −G M_bound / s
Hernquist:  Φ = −G M_b / (s + a_b)
Miyamoto–Nagai:  Φ = −G M_d / √(R² + ε² + (a + √(z² + b²))²)   (z: along the disk normal)

In the inner loop of the star calculation, μ(x)/x² is interpolated from an 8192-entry table (w = x/(1+x)). Inside the halo (x ≤ 25) the relative error is at most 1.2×10⁻⁶. In tests, the acceleration of every component agrees with the numerical derivative of the potential to within 10⁻⁶. A Milky Way–like galaxy (stars 6×10¹⁰, halo 10¹², c = 10, R = 10) has a circular speed of 206 km/s at 8 kpc.

4. Initial conditions

  • Disks (spiral and barred): exponential surface density in radius (truncated at R). 62% of disk tracers are placed in two logarithmic spiral-arm patterns; barred galaxies get a bar pattern inside 0.25R. Tangential velocity is the in-plane circular speed in the whole field of the same galaxy. Height z ~ N(0, h_z), vertical velocity v_z ~ N(0, ν h_z), h_z = 0.08 R_d (irregular 0.25 R_d). ν² = ∂²Φ/∂z² is computed numerically. Radial velocity dispersion is 0 (a cold disk).
  • Irregular: a thick rotating disk plus 4 random clumps (40% of the particles).
  • Bulges and elliptical galaxies: an isotropic Eddington distribution function is built numerically for each galaxy, using the Hernquist tracer density and the spherical average of the field (MN via a 16-point Gauss–Legendre monopole). It uses a 640-cell logarithmic grid, 512 energy bins and 96-point integration, with the cumulative maximum as the upper bound for rejection sampling. Elliptical galaxies are sampled to 2.5R, bulges to 10a_b.
  • Dust: 15% of spiral-arm particles and 4% of background disk particles are shown as dust (about 10.8% of disk particles).
  • Initial stripping: a galaxy that already starts inside a big halo starts stripped to its tidal radius. This only trims the edge and moves no mass or momentum, so other galaxies’ halos and every velocity the user set stay as they are. The stars’ initial velocities are computed in the trimmed field. Distances closer than 10⁻³ kpc are clamped to that value, so stripping is continuous.
  • Mirrored pair placement reduces the center bias from a finite number of particles.

Stability in isolation over 1 Gyr: for all four types, the 25/50/75/90% radius quantiles change by less than 10% (about ±5% in trial runs). The vertical rms of disks grows by less than 25%, and Σv²/Σ(−r·a) for elliptical galaxies stays within 0.93–1.07.

5. Dynamical friction

When satellite s passes through host h (distance r, relative velocity u):

ρ_h(r)  = ρ_NFW,h(√(r² + R_half,s²)) (for r < r_t,h) + ρ_Hernquist,h
σ_h²    = V_max,h² [1.4393 x^0.354 / (1 + 1.1756 x^0.725)]² + G M*_h / [6(r + R_half,h)]   (Zentner & Bullock 2003; r = distance between the two centers)
lnΛ     = ln(1 + M_h/M_s)
a_df    = −κ 4π G² M_s ρ_h lnΛ [erf X − 2X e^(−X²)/√π] u/|u|³,   X = |u|/(√2 σ_h),   κ = 0.5

Both directions (satellite through host, host through satellite) are combined with mass weights (M_h/(M_s+M_h), M_s/(M_s+M_h)). They are applied as equal and opposite impulses, conserving the pair’s momentum. Each half step reduces the relative velocity by f = 1 − exp(−γΔt) and records the kinetic energy removed, ½μu²f(2−f), in an energy ledger.

BK08 calibration. The satellite enters at the host’s r200 on an orbit with r_c(E) = 0.8 r200, and the merger time is taken when j/j0 < 0.05.

Mass ratio Circularity 0.4 0.6 0.8
0.05 1.63 1.17 1.16
0.10 0.91 0.87 0.80
0.20 0.97 0.91 0.82
0.30 1.04 0.95 0.85

(Model/BK08 ratio, median 0.928, range 0.80–1.63.) A radius-based Coulomb logarithm with instant stripping reversed the circularity trend (6.3× at mass ratio 0.3, circularity 0.4), so this form was chosen.

6. Tidal stripping

For each pair with mass ratio q = M_s/M_h < 1, for the lighter galaxy:

r_t = r [M_s(<r_t) / ((2 − dlnM_h/dlnr) M_h(<r))]^(1/3)        (King 1962, bisection)
ΔM  = (M_bound − M_halo,s(<r_t)) · (1 − exp(−A Δt / T_orb)),   T_orb = 2πr / v_c,h(r),   A = 0.6
  • Applied once per 0.5 Myr outer step (initial stripping at the start only trims, as in §4). The stripped mass is added to the host halo’s normalization (keeping its shape) and moved to the host, and the host velocity is updated by momentum conservation.
  • Mass and momentum are conserved. Because mass moves between galaxies, the centers’ energy is not conserved (in reality the stripped matter forms a common halo).
  • Two galaxies of exactly equal mass do not strip each other (neither is lighter). The slightly lighter one is stripped. Nothing is stripped if the host has no halo.

7. Integration, performance and records

  • Gravity uses kick–drift–kick leapfrog, with friction applied in the half steps before and after. Stripping is applied after the drift and before the force calculation. The star calculation does not affect the centers, so the minimap preview (centers only) and the full simulation produce bit-for-bit identical center paths.
  • Inner steps: ω_max² takes the sum of the two largest values of max_r{g/r} over the galaxies. 0.5 Myr is split by powers of two so that ω_max·h ≤ 0.5. Two overlapping centers in a merger are the realistic worst case.
  • Performance (Apple M5 laptop, median per 0.5 Myr): 12,000 stars and 2 galaxies 0.595 ms, 32,000 stars and 4 galaxies 1.911 ms, an extreme setting (stellar mass 2×10¹¹, halo 4×10¹², R = 3, gravity 2×) 14.2 ms (inner step 0.03125 Myr). Rendering and worker messaging are excluded.
  • Computation uses Float64; Float32 is used to send data to the screen. One request at a time, at most 32 basic steps.
  • Up to 121 snapshots are kept, thinned to 12.5 → 25 → 50 → 100 Myr. They store positions, velocities, centers, halos (normalization, edge, accumulated mass), overlap clocks, events and the energy ledger.

8. Presets and checks

Preset Initial values (summary) Pass criteria Measured
Two galaxies brush past Stars 5/3.5, halos 8.5/6 (×10¹¹), 120 kpc, relative tangential 70 km/s, disk tilt 0°/20°, prograde First approach 10–20 kpc, later max/first approach ≥ 1.6, overlap 0.8–2.0 Gyr, tails ≥ 10% 11.4 kpc (0.78 Gyr), 19.3 kpc (1.70×), 1.08 Gyr, 10.6%
Make a cartwheel Target stars 6, halo 10, R 14 (disk normal z), companion elliptical stars 0.8, −100 km/s from (1, 0, 80) kpc At +40/+80/+120 Myr the radius of the outward-spreading ring (maximum density ratio found outside the previous ring radius −1.5 kpc) grows; density ratio > 1.4 at +80 Myr about 4.9 → 7.9 → 10 kpc, 1.93
A giant and a small neighbor Barred: stars 8, halo 13; satellite stars 0.5 (automatic halo), 80 kpc, 160 km/s Satellite mass ≤ 50% at 2 Gyr, j/j0 < 0.05 within 1–4 Gyr 22%, 2.0 Gyr
A dance of three A bound system of three galaxies Finite for 10 Gyr, momentum error < 10⁻⁹ Pass
A lone spiral Stars 5, halo 8.5, R 12 Stability in §4 Pass
A fast flyby Stars 1/0.9 (automatic), 150 kpc, relative 600 km/s, impact parameter 25 kpc Closest > 15 kpc, > 1000 kpc after 10 Gyr 21 kpc, 4600 kpc
The Milky Way’s future Table below Coordinate conversion checks, ensemble 0.05–0.75 Below

Halos of the disk-galaxy presets follow the Milky Way’s ratio (halo ≈ 17× the stellar mass; Sawala 2025’s 10¹² M☉ / 6×10¹⁰ M☉). The automatic (Moster) halo is the default for the user’s own experiments.

The Milky Way’s future — inputs from Table 1 of Sawala et al. 2025 (arXiv:2408.00064):

Galaxy M200 (10¹⁰ M☉) Distance modulus Line-of-sight velocity (km/s) Proper motion μα*, μδ (μas/yr) Disk
Milky Way 100 ± 20 — — — i = 0 (scene XZ), clockwise seen from the north galactic pole
M31 130 ± 40 24.407 ± 0.032 −301 ± 1 48.9 ± 10.5, −36.9 ± 8.1 i = 77.5°, near side NW, approaching side SW
M33 30 ± 10 24.67 ± 0.07 −179.2 ± 1.8 31 ± 19, −29 ± 16 i = 56°, receding side PA 23°, near side west is an unverified assumption
LMC 15 ± 5 18.477 ± 0.026 262.2 ± 3.4 1910 ± 20, 229 ± 47 i = 34°, near side NE, clockwise on the sky

Concentration is 10 ± 2. The galactocentric frame uses the astropy defaults (8.122 kpc, z_sun 20.8 pc, v_sun = (12.9, 245.6, 7.78) km/s), and scene coordinates are (x_gc, z_gc, −y_gc). Conversion checks: M31’s galactocentric distance 765 kpc, approach velocity −114.5 km/s, tangential velocity 66.7 km/s. LMC position (−0.6, −41.0, −26.9) kpc, velocity (−37, −226, 228) km/s.

Ensemble (400 runs, Gaussian truncated at ±2σ, entering within 20 kpc counted as a merger):

Configuration This model Sawala 2025
Milky Way + M31 29% 44%
+ M33 42% 63%
+ LMC 28% 37%
All 4 galaxies 36% 54%

The tendency of M33 to raise the probability and the median merger time (6.6–7.1 Gyr; Sawala 7.6 Gyr) agree. The LMC’s lowering effect barely shows in this model (−1 point; Sawala −7 points). Overall, this model’s probabilities are lower. In trial runs, κ = 1 (uncalibrated Chandrasekhar) gave 47%/54%, almost the same as Sawala, but the BK08 comparison drifted to 0.4–0.7×. This model takes the N-body results (BK08) as its reference. The difference between the two results shows the effect of the choice of model, so the app shows both.

Automated checks:

  1. Cosmological constants and relations, SHMR round trip (1e-6)
  2. Acceleration of each component = potential gradient, Milky Way–like rotation speed, NFW table precision
  3. Conservation of the centers’ energy (friction and stripping off, 5 Gyr, < 10⁻⁶), conservation of mass and momentum (on), stripping direction, zero dark matter, overlapping centers, inner steps
  4. BK08 calibration
  5. Positivity of the Eddington distribution, sample distributions
  6. Determinism, uniform motion with zero gravity, preview = center paths of the full simulation, particle types, finiteness under extreme settings
  7. Stability in isolation
  8. Overlap mark does not interfere, unbound flybys, friction off / zero gravity, convergence when halving the step
  9. Preset pass criteria
  10. Local Group coordinates, disk orientations and ensemble
  11. Rewind, branching and repeatable events, star tracking
  12. Validation of v2 settings, conversion from v1

Browser tests check, in real Chrome, a 32,000-star run to 10 Gyr, that empty space stays dark, that merging centers do not go black with dust, switching between star tracking and galaxy following, minimap dragging with position and speed readouts, and the ensemble, including ignoring ensemble results that arrive late.

These criteria are checks of the implementation and the numerics. Checks of physical error rates against observations or research N-body runs are limited to the BK08 merger times and the Sawala 2025 ensemble comparison.

9. Questions to ask when requesting a review

  • For encounters with mass ratio above 0.3 (comparable masses), are κ = 0.5 and the mass-ratio Coulomb logarithm appropriate? This is outside the BK08 range and gives friction about 2× weaker than the Sawala model.
  • The “only the lighter galaxy is stripped” rule is discontinuous near q ≈ 1. Is there a better symmetric rule?
  • What bias does the difference between the disk tracer distribution (exponential, h_z = 0.08 R_d) and the MN potential introduce into the results?
  • How does softening the force between centers by the other galaxy’s stellar half-mass radius distort the final stage of a merger?
  • As the next step in accuracy, which comes first: live halos and disk self-gravity (GPU N-body), or gas and star formation?

10. Theory and comparison sources

  • Navarro, Frenk & White 1997 — NFW profile
  • Dutton & Macciò 2014 — concentration–mass relation
  • Moster, Naab & White 2013 — stellar-mass–halo-mass relation
  • Miyamoto & Nagai 1975 · Hernquist 1990 — disk and bulge potentials
  • Bovy 2015 (galpy, MWPotential2014) — Milky Way potential ratios
  • Chandrasekhar 1943 · Zentner & Bullock 2003 — dynamical friction, NFW velocity dispersion approximation
  • Boylan-Kolchin, Ma & Quataert 2008 — N-body calibrated merger-time formula
  • King 1962 · Taylor & Babul 2001 — tidal radius, mass-loss rate
  • Bartelmann 1996 — projected NFW surface density (dark matter view)
  • Toomre & Toomre 1972 · Lynds & Toomre 1976 — tidal tails, ring galaxies
  • Sawala et al. 2025, Nature Astronomy — Milky Way–Andromeda merger probability
  • Salomon et al. 2021 · McConnachie 2012 · van der Marel & Kallivayalil 2014 — M31 proper motion, Local Group data, LMC rotation
  • Bovy, Dynamics and Astrophysics of Galaxies — Eddington inversion, spherical distribution functions