Kepler orbit simulator: a planet of negligible mass orbits a fixed central star under Newtonian gravity, with position and velocity integrated every frame using 4th-order Runge-Kutta (RK4). The initial tangential speed is set as a multiple of the local circular speed, producing anything from a perfect circle to a stretched ellipse. Perihelion, aphelion, eccentricity, semi-major axis and orbital period are derived from conserved specific energy and angular momentum, and Kepler's second law is demonstrated with two equal-area sweep wedges, one tracking the planet and one on the opposite side of the orbit.
Kepler's 3rd law: T² ∝ a³
Johannes Kepler derived three empirical laws from Tycho Brahe's planetary observations. First, every planet moves on an ellipse with the Sun (or any central mass) at one focus, not at the centre. Second, a line joining the planet to that focus sweeps out equal areas in equal times — planets speed up near perihelion (closest approach) and slow down near aphelion (farthest point), a direct visual consequence of conserved angular momentum. Third, the square of the orbital period is proportional to the cube of the semi-major axis, T² ∝ a³, so farther planets take disproportionately longer to complete an orbit. This simulation reproduces all three: the traced path is a true ellipse, the two shaded wedges sweep equal areas in equal time regardless of where the planet is, and the telemetry panel updates T and a together whenever you change the orbit's shape.
Kepler found these laws empirically, decades before anyone knew why they held. Newton later showed that all three follow directly from a single inverse-square gravitational force, F = −GMm/r², combined with calculus and his second law of motion. Here that force law is expressed as an acceleration, a = −μr/r³ (with μ = GM), and advanced forward in time using 4th-order Runge-Kutta (RK4) integration rather than the closed-form conic-section solution. The pure two-body problem does have an exact analytic solution, but RK4 is the general numerical technique that extends seamlessly to perturbed orbits, multi-body systems and non-Keplerian forces — it is essentially the same family of integrator that real spacecraft trajectory designers use to plan interplanetary missions, just applied here to the simplest possible case so its accuracy can be checked against the exact ellipse.
What does this simulation actually show?
A single planet of negligible mass orbiting a fixed star under Newtonian gravity. Its position and velocity are integrated every frame with RK4. You control the initial speed at the starting point as a multiple of the local circular speed, which determines whether the resulting path is a circle or a stretched ellipse, and the panel reports the orbit's period, perihelion, aphelion, eccentricity and semi-major axis live.
Why do planets move faster near perihelion?
Angular momentum, h = r·v (for the tangential component), is conserved throughout the orbit. As the planet approaches the focus, r shrinks, so the tangential speed must rise to keep r·v constant. The same conservation law is why the two shaded sweep wedges have equal area even though the one nearer perihelion is short and wide while the one nearer aphelion is long and narrow.
What is the relationship between orbital period and orbital size?
Kepler's third law: T² ∝ a³, or exactly T = 2π√(a³/μ) for this simulation's central mass. Doubling the semi-major axis multiplies the period by 2√2 ≈ 2.83, not just 2. Drag the speed slider toward the extremes and watch the period figure grow as the orbit stretches into a wider ellipse.
A circle is only the special case where the initial speed exactly equals the local circular speed, v_circ = √(μ/r). Any other tangential speed still produces a closed, bound orbit as long as the total specific energy ε = v²/2 − μ/r stays negative, but the path becomes an ellipse whose eccentricity grows the further the initial speed departs from v_circ. At the slider's default value of 1.00× the orbit is a near-perfect circle; moving the slider away from 1.00× in either direction stretches it.
If the speed reaches √2 times the circular speed, the specific energy ε becomes exactly zero and the trajectory becomes a parabola that never returns — the escape velocity. Above that, ε is positive and the path is an open hyperbola. This simulator caps the slider well below that threshold (at 1.30×, comfortably under √2 ≈ 1.414) so every orbit you can select stays a closed, bound ellipse.
Fourth-order Runge-Kutta estimates the state a short time step ahead by sampling the acceleration at four points within that step and combining them with carefully chosen weights, which cancels error terms up to fourth order. For the pure two-body problem an exact closed-form ellipse exists, so RK4's job here is really a consistency check: if the numerically traced path visibly drifted or precessed away from the analytic ellipse drawn underneath it, that would signal an integration error. Running dozens of small RK4 substeps per animation frame keeps that drift imperceptible over many orbits.
From the conserved specific energy ε = v₀²/2 − μ/r₀ and specific angular momentum h = r₀v₀ at the starting point, the semi-major axis is a = −μ/(2ε) and the eccentricity is e = √(1 − h²/(μa)). Perihelion is then a(1−e) and aphelion is a(1+e). This works regardless of whether the starting point happens to be the near point or the far point of the resulting ellipse — the algebra self-corrects either way.
Because they are, by construction: Kepler's second law states the areal sweep rate dA/dt = h/2, a constant fixed entirely by the orbit's angular momentum. Both wedges are drawn using the same fixed time interval (2% of the orbital period), so both cover almost exactly the same area no matter where on the ellipse they are placed — a fast, narrow wedge near perihelion and a slow, wide one near aphelion.
It treats the orbiting body as having negligible mass, so it never pulls back on the central star (a true two-body problem would have both bodies orbit their common centre of mass). It also ignores any third bodies, relativistic corrections, radiation pressure, and non-spherical mass distributions — all real effects that perturb actual planetary and satellite orbits away from perfect, closed ellipses over long timescales.
The same inverse-square gravity and RK4-style numerical integration govern the orbits of planets, moons, comets, and every artificial satellite and interplanetary spacecraft. Mission designers use higher-order variants of exactly this technique to plan trajectories, compute transfer orbits and predict where a spacecraft will be years into a mission, before any perturbations from other bodies are even added.