← 🔭 Space & Astronomy

🌌 Galaxy Formation

Bodies: 700
FPS: —
Time: 0 Myr
Total mass: —
Kinetic E: —
Potential E: —
Virial ratio 2T/|U|: —
Algo: Barnes-Hut
Clump 1
Clump 2
Clump 3
Clump 4+
Drag — pan · Scroll — zoom

🌌 N-Body Galaxy Formation with Dark Matter Halo

A genuine N-body simulation of galaxy formation: several small, cold, scattered proto-galactic clumps of stars collapse and merge under real Barnes-Hut gravity, integrated with a symplectic leapfrog scheme, while a dark matter halo strengthens the binding — watch the virial ratio settle toward equilibrium as the merger plays out.

🔬 What It Demonstrates

Hierarchical galaxy formation: scattered clumps fall together under mutual gravity, merge, and violently relax into a single bound structure. Real kinetic and potential energy are tracked live to compute the virial ratio 2T/|U|, which starts well below 1 during collapse and settles near 1 once the system virializes.

🎮 How to Use

Drag to pan, scroll to zoom. Set the number of clumps, total bodies and initial spread (need Restart), and adjust the dark matter halo strength, gravity G and softening live. Raise the halo slider and watch the clumps bind together faster.

💡 Did You Know?

Real galaxies are thought to have assembled the same way — small dark-matter-dominated clumps merging repeatedly over billions of years. This simulation compresses that hierarchical clustering into seconds using the same Newtonian gravity and the same virial theorem astronomers use to weigh real galaxy clusters.

About this simulation

Written by MySimulator Team · Reviewed by MySimulator Editorial Review

Last updated: 13 September 2026

Unlike a simulation that starts from an already-formed rotating disk, this one starts from the formation problem itself: several small, cold clumps of stars scattered across a wide region, with no organised rotation and barely any internal motion. A Barnes-Hut quadtree sums real Newtonian gravity between every star each frame in O(N log N) time, integrated with a symplectic leapfrog scheme, while an optional dark matter halo adds a smooth background pull toward the system's own centre of mass. Nothing about the eventual shape is scripted — the clumps fall together, collide, and merge purely because gravity pulls them that way.

🔬 What it shows

Hierarchical galaxy formation from first principles: cold clumps under-bound relative to the whole system collapse, merge violently, and relax toward a bound quasi-equilibrium, tracked live through the virial ratio 2T/|U| computed from real kinetic and potential energy — not asserted, measured.

🎮 How to use

Set clump count, total bodies and initial spread (apply on Restart), and tune dark matter halo strength, gravity G and softening ε live. Watch the virial ratio: it dips well below 1 while clumps are still falling and merging, then climbs back toward 1 as the system settles. Drag to pan, scroll to zoom.

💡 Why the virial ratio matters

The virial theorem says a bound, relaxed system satisfies 2T + U = 0, so 2T/|U| should hover near 1. Watching that ratio swing during the merger and then settle is direct evidence the collapse is being driven by the actual gravity computed each frame, not a preset animation.

Frequently asked questions

How is this different from a simulation of an already-formed galaxy disk?

Simulations of an existing disk (such as this site's 2D Galaxy) start stars already on near-circular orbits derived from a target rotation curve. This one starts from scattered, cold, unbound clumps and lets pure self-gravity build the bound structure from scratch — the formation process itself, not the end state.

What integration method does this use, and why does it matter?

It uses a symplectic leapfrog (kick-drift-kick) scheme rather than plain Euler integration. Leapfrog conserves energy much better over long runs, which matters here because the simulation needs to be trusted to show a genuine virial ratio rather than one drifting from numerical error.

What does the dark matter halo slider actually change?

It adds a smooth, non-clumpy background mass centred on the system's live centre of mass, pulling every clump inward and strengthening the binding between them. Raising it visibly speeds up how quickly the clumps fall together and merge — the same invisible-mass effect astronomers use to explain why real galaxies and clusters stay bound.

What is the virial ratio and why does it change over time?

The virial ratio 2T/|U| compares twice the kinetic energy to the magnitude of the potential energy. A bound, relaxed system settles near 1. Here it starts well below 1 (the clumps are cold and still falling), spikes during the violent merger, and gradually relaxes back toward 1 as the system reaches quasi-equilibrium — computed live from real positions and velocities, not scripted.