Physics · Intermediate

Kepler orbits

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

Kepler's three laws describe how planets move around the Sun in ellipses, sweep out equal areas in equal times, and obey a fixed relation between period and size of orbit. They follow from Newton's inverse-square law of gravity and conservation of angular momentum and energy.

Intuition

Gravity pulls a planet toward the Sun with a force that weakens as the square of distance. A planet with sideways velocity keeps falling toward the Sun but keeps missing it, so it curves around. Because gravity points exactly at the Sun, it exerts no torque about the Sun, so angular momentum is conserved. When the planet is close, it must move faster to keep the same angular momentum; when far, it slows. The path that results is a conic section: for bound orbits, an ellipse with the Sun at one focus. Larger orbits have weaker gravity and longer paths, so they take disproportionately longer, giving the period-size law.

Key equations

r=a(1−e2)1+ecos⁡θ
(1)

First law: the orbit is an ellipse with semi-major axis a and eccentricity e, with the Sun at a focus.

dAdt=L2m=constant
(2)

Second law: the line from Sun to planet sweeps equal areas in equal times, because angular momentum L is conserved.

T2=4π2GMa3
(3)

Third law: the square of the period is proportional to the cube of the semi-major axis.

E=−GMm2a
(4)

Total orbital energy depends only on the semi-major axis.

v2=GM(2r−1a)
(5)

Vis-viva equation: speed at any distance r along the orbit.

Derivation

  1. Start with the central force F=−GMm/r2 pointing toward the Sun. Torque about the Sun is zero, so L=mr2(dθ/dt) is constant.
  2. The area swept in time dt is dA=12r2dθ, so dAdt=L2m is constant. This is the second law.
  3. Using the substitution u=1/r, the radial equation of motion becomes d2udθ2+u=GMm2L2.
  4. The solution is u=GMm2L2(1+ecos⁡θ), which is the equation of a conic section; for e<1 it is an ellipse. This is the first law.
  5. The total area of the ellipse is πab. Dividing by the area rate gives T = πab / (L/2m) = 2πmab/L.
  6. With b2=a2(1−e2) and L2/(GMm2)=a(1−e2), we get T2=4π2a3/(GM). This is the third law.

Worked example

Problem

A comet has perihelion distance 0.60 AU and aphelion distance 35.0 AU. Find its semi-major axis, period in years, and the ratio of its speeds at perihelion and aphelion.

  1. Semi-major axis: a = (0.60 + 35.0)/2 = 17.8 AU.
  2. Period using T2=a3 with years and AU: T=17.81.5.
  3. 17.8^1.5 = 17.8 × √17.8 ≈ 17.8 × 4.219 ≈ 75.1 years.
  4. Angular momentum conservation at the two turning points: r_p v_p = r_a v_a.
  5. So v_p/v_a = r_a/r_p = 35.0/0.60 ≈ 58.

Answer a = 17.8 AU, T ≈ 75 years, and the comet moves about 58 times faster at perihelion than at aphelion.

Common mistakes

  • Thinking the Sun is at the center of the ellipse; it is at one focus.
  • Believing the planet speeds up because it is hotter or pushed along; speed changes come from conservation of angular momentum.
  • Using T2=a3 with units other than years and AU (it holds only in those units, for the Sun).
  • Using the orbit's farthest distance instead of the semi-major axis in the third law.
  • Assuming the second law means equal distances in equal times rather than equal areas.

Animation

Animation coming soon

The animated version of this lesson is being prepared for the web. In the Signals AI app, lessons are drawn step by step.

Code

scene.py(91 lines)
import sys
from manim import *
from blocks import *
import numpy as np

E_ORB = 0.6      # eccentricity
A_SEMI = 1.0     # semi-major axis (model units)
GM = 4 * np.pi ** 2  # units: AU, years


def kepler_E(M, e):
    """Solve Kepler's equation M = E - e sin E by Newton iteration."""
    E = M if e < 0.8 else np.pi
    for _ in range(50):
        E = E - (E - e * np.sin(E) - M) / (1 - e * np.cos(E))
    return E


def simulate(e=E_ORB, a=A_SEMI, n=240):
    """Fixed-step orbit from Kepler's equation; returns list of (t, x, y, r, speed)."""
    T = a ** 1.5
    out = []
    for k in range(n + 1):
        t = T * k / n
        M = 2 * np.pi * t / T
        E = kepler_E(M, e)
        x = a * (np.cos(E) - e)
        y = a * np.sqrt(1 - e * e) * np.sin(E)
        r = np.hypot(x, y)
        v = np.sqrt(GM * (2 / r - 1 / a))
        out.append((t, x, y, r, v))
    return out


TRACE = simulate()


def sector_area(i, j):
    """Area swept by the radius vector between samples i and j (triangle fan)."""
    s = 0.0
    for k in range(i, j):
        s += 0.5 * abs(TRACE[k][1] * TRACE[k + 1][2] - TRACE[k + 1][1] * TRACE[k][2])
    return s


class Main(Scene):
    def construct(self):
        self.camera.background_color = "#101418"
        TitleCard(self, "Kepler orbits", "Equal areas in equal times")
        scale = 3.2
        c0 = LEFT * 1.5 + DOWN * 0.1
        pts = [c0 + scale * np.array([p[1], p[2], 0]) for p in TRACE]
        orbit = VMobject(color=C_MAIN).set_points_smoothly(pts)
        sun = Dot(c0, color=C_ACCENT, radius=0.14)
        self.play(Create(orbit), FadeIn(sun))
        planet = Dot(pts[0], color=C_GOOD, radius=0.1)
        self.add(planet)
        StepCaption(self, "Planet moves fast near the Sun, slow far away")
        # two equal-time sectors: near perihelion and near aphelion
        n = len(TRACE) - 1
        span = 24
        segs = [(0, span, C_BAD), (n // 2 - span // 2, n // 2 + span // 2, C_ACCENT)]
        areas = []
        for i, j, col in segs:
            self.play(MoveAlongPath(planet, VMobject().set_points_smoothly(pts[:1] + pts[i:j + 1]) if i else
                                    VMobject().set_points_smoothly(pts[i:j + 1]),
                                    rate_func=linear, run_time=2.2))
            poly = Polygon(c0, *pts[i:j + 1], color=col, fill_opacity=0.5, stroke_width=1)
            self.play(FadeIn(poly), run_time=0.5)
            areas.append(sector_area(i, j))
        txt = Text(f"Areas: {areas[0]:.3f} and {areas[1]:.3f}", font_size=26,
                   color=WHITE).to_edge(RIGHT, buff=0.4).shift(UP)
        self.play(FadeIn(txt))
        law = MathTex(r"\frac{dA}{dt}=\text{const}", font_size=40).next_to(txt, DOWN, buff=0.5)
        self.play(Write(law))
        StepCaption(self, "Equal times sweep equal areas: Kepler's second law")
        self.wait(1)


if __name__ == "__main__" and "--selftest" in sys.argv:
    assert abs(TRACE[0][1] - A_SEMI * (1 - E_ORB)) < 1e-9
    assert abs(TRACE[-1][1] - TRACE[0][1]) < 1e-6
    rs = [p[3] for p in TRACE]
    assert abs(min(rs) - A_SEMI * (1 - E_ORB)) < 1e-3
    assert abs(max(rs) - A_SEMI * (1 + E_ORB)) < 1e-3
    n = len(TRACE) - 1
    a1 = sector_area(0, 24)
    a2 = sector_area(n // 2 - 12, n // 2 + 12)
    assert abs(a1 - a2) / a1 < 0.01
    assert TRACE[0][4] > TRACE[n // 2][4]
    print("ok")

The Manim scene code that draws this lesson's animation in the Signals AI app (Python, Manim Community).

ccBYNC© 2026 SignalsLab. Lesson text shared as is under CC BY-NC 4.0.