From observation to law, then from law to force
Johannes Kepler spent decades fitting Tycho Brahe's naked-eye observations of Mars and derived three empirical rules for planetary motion in the early 1600s, decades before anyone knew why they were true. It took Isaac Newton's law of universal gravitation, F = -GMm/r² directed along the line joining the two bodies, to show that all three of Kepler's laws are not independent facts about the solar system but a single mathematical consequence of one force law applied to the two-body problem.
First law: ellipses, not circles
Solving Newton's equations for a bound two-body orbit under an inverse-square force yields a conic section with the central mass sitting at one focus, not the center. For bound orbits (total energy negative) that conic is always an ellipse; a circle is simply the special, exact case of eccentricity e = 0, requiring the launch speed and radius to satisfy one precise relationship. Change the launch speed even slightly and the orbit stretches into an ellipse with the planet closest to the star at perihelion and farthest at aphelion, exactly the shape Kepler had to infer from Mars's stubbornly non-circular path.
Second law: equal areas, a consequence of angular momentum
Kepler's second law says the line from the star to the planet sweeps out equal areas in equal times - the planet moves fastest near perihelion and slowest near aphelion. Because the gravitational force always points along that same line (a "central force"), it exerts zero torque about the star, so angular momentum L = m·r×v is conserved throughout the orbit. The rate at which area is swept out is exactly dA/dt = L/(2m), a constant - so equal areas in equal times is nothing more than conservation of angular momentum, dressed in geometric language.
Third law: period squared, semi-major axis cubed
T² = (4π² / G·M) · a³
T = orbital period
a = semi-major axis (average of closest and farthest distance)
M = mass of the central body (the planet's own mass drops out
when it is much smaller than M)
Kepler's third law falls out of balancing gravitational force against the centripetal requirement for a closed orbit and integrating over one full period. It is the law astronomers actually use the most: measure a planet's (or a moon's, or a binary star's) period and semi-major axis, and the central mass M pops straight out - this is literally how the masses of the Sun, the planets with moons, and countless exoplanet host stars have been weighed without ever putting them on a scale.
Simulating it: why the integrator matters
The equations of motion themselves are simple - acceleration equals -GM r̂/r² - but numerically integrating them stably over many orbits is not automatic. Naive explicit Euler integration (advance position using the old velocity, then update velocity) systematically injects energy into the system every single step; a circular orbit simulated this way visibly spirals outward, and the effect gets worse, not better, the longer the simulation runs. Fourth-order Runge-Kutta (RK4) fixes this for the timescales relevant here by sampling the acceleration at four points across each step - at the start, twice at the midpoint with trial half-steps, and at the projected endpoint - and combining them into an update whose local error scales as the time step to the fifth power, dramatically better behavior over the dozens of orbits a demo needs to render convincingly.
The energy that decides the shape
One more piece ties the whole picture together: the orbit's total mechanical energy, E = ½mv² - GMm/r, determines which conic section results. E < 0 gives a bound ellipse (Kepler's regime); E = 0 gives a parabolic trajectory that just barely escapes to infinity with zero speed left over; E > 0 gives a hyperbolic flyby that escapes with speed to spare. Adjusting a launch speed in a simulation like this one is really just dialing E up or down, and watching the orbit morph from a tight ellipse through a near-circle, a wide ellipse, and finally break open into a parabola and a hyperbola is the fastest way to see all three of Kepler's laws - and their limits - in one continuous slider.
Frequently asked questions
Why are orbits ellipses rather than circles?
A circle is only the special case of an ellipse with zero eccentricity, requiring an exact launch speed for a given radius. Any other combination of position and velocity consistent with a bound orbit under an inverse-square force traces an ellipse with the central body at one focus - Newton showed this follows directly from solving the two-body equations of motion.
What does Kepler's second law mean physically?
Equal areas in equal times is a direct consequence of conservation of angular momentum. A planet moves fastest at perihelion (closest approach) and slowest at aphelion (farthest point), and the product of speed and distance from the focus along the orbit stays such that the swept area rate never changes.
Why does the simulation use RK4 instead of simple Euler integration?
Explicit Euler integration systematically adds energy to a gravitational orbit, causing it to spiral outward over time even with a small time step. Fourth-order Runge-Kutta samples the gravitational acceleration four times per step and blends them, keeping the orbit's shape and energy close to correct over many revolutions.
Try it live
Everything above runs in your browser - open Kepler Orbits and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Kepler Orbits simulation