# Kepler Orbit

> Watch a planet orbit the sun on an ellipse and sweep equal areas in equal times. Drag the eccentricity e₀ from a circle to a long ellipse.

A planet moves on an ellipse with the sun at one focus (Kepler's first law), and the line from the sun to the planet sweeps equal areas in equal times (the second law). The orbit in this document is the polar curve $r = p/(1 + e_0\cos\theta)$, the conic with a focus at the origin and the eccentricity $e_0$. The semi-major axis is fixed at 1, so $p = 1 - e_0^2$. By the third law the period then does not depend on $e_0$: a change of $e_0$ changes the shape of the orbit, not the speed of the animation.

The time is the mean anomaly $T$, which grows at a constant rate: one loop of $T$ from $0$ to $2\pi$ is one orbit. To place the planet, the document solves Kepler's equation $T = E - e_0\sin E$ for the eccentric anomaly $E$. The equation has no closed-form solution, so $E(m)$ is four Newton steps from $m + e_0\sin m$, accurate to $2 \cdot 10^{-11}$ for every $e_0$ up to $0.75$. The planet is then at $(\cos E - e_0, \sqrt{1 - e_0^2}\sin E)$.

The blue sector is the area that the line from the sun to the planet has swept in the last twelfth of the period. Its area is always $\pi\sqrt{1 - e_0^2}/12$: long and thin far from the sun, short and wide near it. $T$ animates when the document opens, one orbit every 8 seconds; the slider for $e_0$ runs from $0$, a circle, to $0.7$.

- [Open the interactive version](https://graph-paper.io/showcase/en/kepler-orbit)
- [Learn more on Wikipedia](https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion)
