Celestial Body Dynamics: Gravity & Orbits (2D)
2D orbital-mechanics lab: a real inverse-square gravity integrator (RK4) drives one body around a central mass — set the mass, starting distance and launch speed and watch circular, elliptical, parabolic or hyperbolic orbits emerge from the same formula, with live energy and eccentricity readouts.
This 2D companion strips the 3D scene down to the actual physics behind orbital motion: a single body orbits a fixed central mass under Newtonian gravity, stepped forward with a 4th-order Runge–Kutta integrator so total energy stays nearly constant instead of drifting. Sliders set the central mass, the starting distance and the launch speed as a multiple of the local circular speed — launch at exactly that speed and the path closes into a circle, launch slower or faster and it stretches into an ellipse, and past √2 times circular speed the body escapes on a parabolic or hyperbolic path, all read live off the same eccentricity and energy formulas that describe real orbits.
2D orbital-mechanics lab with an RK4-integrated inverse-square gravity field, live eccentricity/period/energy readouts, and a trail that traces circular, elliptical, parabolic and hyperbolic orbits from the same launch-speed control.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install
The shape is set entirely by the body's specific orbital energy and angular momentum at launch. Slower than circular speed pulls periapsis inward (ellipse), faster stretches apoapsis outward (ellipse), exactly circular speed gives zero eccentricity, and past the local escape speed (√2 × circular) the energy turns positive and the body never returns.
Plain Euler integration systematically leaks or adds orbital energy every step, so an orbit that should be a closed ellipse slowly spirals in or out. RK4 evaluates the gravity field at several points within each step, which keeps the total energy reading in the panel essentially flat over long runs.
Eccentricity e is computed from the body's actual energy and angular momentum via e = √(1 + 2EL²/(GM)²) — 0 is a perfect circle, between 0 and 1 is an ellipse, 1 is a parabolic escape, and above 1 is hyperbolic. The period is only meaningful for bound (elliptical) orbits and is derived from the semi-major axis via Kepler's third law.