Interactive Space Physics
Explore the forces that shaped galaxies, solar systems, and everything in between powered by real gravitational physics and real time simulation.
Cosmology
Galaxies are the fundamental building blocks of the large scale universe. They form when gravity causes vast clouds of hydrogen and helium left over from the Big Bang to collapse and fragment into dense stellar nurseries over hundreds of millions of years.
Dark matter plays a critical role: its gravitational scaffolding draws in ordinary baryonic matter, seeding the first protogalactic clumps. As these collapse, conservation of angular momentum spins the infalling gas into a rotating disk, while feedback from supernovae and active galactic nuclei regulate star formation.
At the center of most large galaxies lurks a supermassive black hole that is millions to billions of solar masses whose tidal influence and jet activity profoundly shapes galaxy morphology and star formation history over cosmic time.
Planetary Science
Our solar system formed roughly 4.6 billion years ago from a hot dense, rotating molecular cloud, a solar nebula triggered into collapse, possibly by a nearby supernova shockwave. Gravity drew most of the mass to the center, igniting a protostar that would become the Sun.
The remaining gas and dust flattened into a protoplanetary disk. Within this disk, tiny dust grains collided and stuck together, growing into centimeter-sized pebbles, then kilometer-scale planetesimals, and eventually rocky protoplanets. This accretion process is governed by gravitational focusing, relative velocities, and material strength.
The frost line which is the boundary beyond which volatile ices condense, divided the disk into an inner terrestrial zone (rocky planets) and an outer giant planet zone (gas planets). Jupiter's rapid growth disrupted the asteroid belt and may have deflected water rich carbonaceous asteroids inward, seeding Earth with its oceans.
Algorithms
Simulating N bodies under gravity naively requires O(N²) force calculations per timestep which is prohibitively expensive for even 10,000 particles. The Barnes-Hut tree algorithm, introduced by Josh Barnes and Piet Hut in 1986, reduces this to O(N log N).
The space is recursively subdivided into an octree (or quadtree in 2D). Each internal node stores the total mass and center of mass of all particles in its cell. When computing the force on a particle, distant clusters are treated as single point masses if the cell's angular size falls below a threshold θ (the opening angle). Only nearby cells are expanded for detail.
Lowering θ increases accuracy but slows performance; raising it sacrifices some precision for speed. At θ ≈ 0.5-0.7 the results are nearly indistinguishable from direct summation while running orders of magnitude faster, making real-time galaxy simulation possible.
About This Project
This simulator implements N-body gravitational dynamics using a Barnes-Hut octree in JavaScript. Particle integration uses an adaptive timestep scaling based on local velocities and accelerations.
A custom galaxy generator initializes realistic spiral disks with force and velocity initialization, center of mass momentum removal, and virial rescaling. Dark matter halos, central black holes, disk and bulge components are all configurable in real time.
The renderer uses WebGL for hardware accelerated particle drawing with additive blending, giving the characteristic luminous glow of dense stellar regions. A 6-degree-of-freedom camera lets you orbit, zoom, and pan through the simulation space freely.