← 🔭 Space & Astronomy

☄️ N-Body 2D

Bodies: 300
FPS: —
Time: 0 s
Scenario
Algo: Barnes-Hut
Central star
Small bodies
High velocity
Drag — pan · Scroll — zoom

☄️ N-Body Gravity 2D — Top-Down Simulation

The flat twin of the 3D N-Body Gravity simulation: the same Barnes-Hut gravitational physics, watched from directly above on a 2D canvas — lighter to run and easier to read orbital structure at a glance.

🔬 What It Demonstrates

The identical N-body physics as the 3D version — every particle gravitationally attracts every other, accelerated with a Barnes-Hut octree — but projected onto a flat plane. Stable orbits, galaxy collisions, and Solar System dynamics read clearly from a top-down view.

🎮 How to Use

Drag to pan the view, scroll (or pinch) to zoom. Choose a scenario — galaxy disk, galaxy collision, or Solar System — and adjust gravitational constant G, star mass, softening, and trail length with the sliders.

💡 Did You Know?

The three-body problem — predicting three gravitating masses — has no closed general solution. Henri Poincaré proved this in 1887, marking the birth of chaos theory, 76 years before Lorenz's weather work.

About this simulation

Written by MySimulator Team · Reviewed by MySimulator Editorial Review

Last updated: 28 August 2026

This is the flat, top-down twin of N-Body Gravity: the same N-body problem physics, in which hundreds of masses each attract every other through Newton's inverse-square law of gravity, drawn on a 2D canvas instead of a rotatable WebGL scene. The accelerations are summed with a Barnes-Hut octree that reduces the cost from O(N²) to O(N log N), and positions are advanced by a leapfrog-style integrator run in small sub-steps — identical to the 3D version underneath. Drag to pan, scroll to zoom, and switch between a galactic disk, colliding galaxies, or a scaled Solar System.

🔬 What it shows

Gravitational dynamics of up to 800 bodies, mapped flat. Each frame the net force on every body is computed from a Barnes-Hut octree (or exact O(N²) summation), then velocities and positions are updated by leapfrog integration. Stable circular orbits, merging discs and chaotic close encounters all emerge from the physics rather than being scripted.

🎮 How to use

Sliders set the body count (50–800), central star mass (500–8000), the gravitational constant G (0.1–3), the softening ε (0.5–5) and trail length (0–80). A dropdown switches between galaxy disk, galaxy collision and Solar System; a checkbox toggles Barnes-Hut versus direct summation. Use Restart to rebuild, drag to pan and scroll to zoom.

💡 Why a 2D twin?

A flat top-down view has no WebGL scene to composite, so it renders lighter on low-power and mobile devices, and the disk's spiral structure and orbital resonances are easier to read without needing to rotate the camera to find a good angle.

Frequently asked questions

How is this different from the 3D N-Body Gravity simulation?

The physics is identical — same Barnes-Hut octree, same leapfrog integration, same softened gravity law — only the rendering differs. This version draws bodies on a flat 2D canvas viewed from directly above instead of a rotatable 3D WebGL scene, which is lighter to run and makes orbital structure easier to read at a glance.

What is an N-body simulation?

It is a numerical model of how many masses move under their mutual gravity. Because each body attracts every other, there is no tidy formula for the motion of more than two bodies, so the computer integrates Newton's equations step by step. This simulation handles up to 800 bodies at once.

How does the Barnes-Hut algorithm speed things up?

A naive N-body calculation evaluates every pair of bodies, which costs O(N²) operations per frame. Barnes-Hut instead builds an octree that groups distant clusters of bodies into a single centre of mass, so a faraway group can be treated as one effective particle. This drops the cost to roughly O(N log N); you can toggle it off to compare against exact direct summation.

Is the simulation physically accurate?

The force law, Barnes-Hut grouping and orbital velocities are physically faithful, so the qualitative behaviour — stable discs, tidal tails in collisions and chaotic motion — is genuine. The masses, distances and gravitational constant use simplified simulation units rather than real SI values. It is an accurate teaching model, not a research-grade ephemeris.