Solution (source code)

= Solution

With the <ellipse> center as origin and its major axis horizontal, the auxiliary-circle construction gives particle coordinates $X=a\cos E$, $Y=a\sqrt{1-e^2}\sin E$, while the stellar focus is at $(ae,0)$. Therefore
$$
r\cos f=a(\cos E-e),\qquad r\sin f=a\sqrt{1-e^2}\sin E.
$$
Squaring and adding gives $r^2=a^2(1-e\cos E)^2$. The <Kepler orbit> radius and the anomaly conversion are consequently
$$
\boxed{r=a(1-e\cos E),\qquad
\cos f=\frac{\cos E-e}{1-e\cos E},\qquad
\sin f=\frac{\sqrt{1-e^2}\sin E}{1-e\cos E}.}
$$
Equivalently,
$$
\boxed{\tan\frac f2=\sqrt{\frac{1+e}{1-e}}\tan\frac E2.}
$$
The sine and cosine formulas, or a quadrant-aware angle function, fix the correct branch when using the half-angle relation.