Solution (source code)

= Solution

<Kepler's laws of planetary motion> state that, in the relative two-body description, bound trajectories are <ellipses> with the attracting body at a focus, the <radius> vector sweeps equal <areas> in equal times, and the square of the period is proportional to the cube of the <semimajor axis> for a fixed total <mass>. Their Newtonian derivation is especially informative. With relative coordinate $\mathbf r$ and $\mu_g=G(M+m)$, the inverse-square <acceleration> is $-\mu_g\mathbf r/r^3$. Its zero <torque> conserves $\mathbf h=\mathbf r\times\dot{\mathbf r}$, fixing a plane and the <areal velocity> $h/2$.

For $u=1/r$, the <orbit> equation is $u''+u=\mu_g/h^2$ as a function of polar angle. Therefore
$$
r=\frac{h^2/\mu_g}{1+e\cos(\phi-\phi_0)}.
$$
Bound negative-energy motion has $0\leq e<1$ and semilatus rectum $h^2/\mu_g=a(1-e^2)$. Dividing <ellipse> <area> by <areal velocity> gives
$$
\boxed{T^2=\frac{4\pi^2a^3}{G(M+m)}.}
$$
For a planet much lighter than its star, replace $M+m$ by $M$. Zero-energy and positive-energy encounters are parabolic and hyperbolic rather than periodic <ellipses>. Perturbations from other bodies and departures from point-mass Newtonian gravity can precess or otherwise modify the <orbit>; Kepler's laws are a two-body approximation, not an exact rule for every observed planetary path.