When is the angle around an ellipse, not the angle around an ellipse? This is a problem which tripped me up a few times when working with elliptical orbits and arcs.

The problem

This problem arises when we use a parametric equation for an ellipse, defining the point on an ellipse as a function of $\theta$ with these two equations.

$x = a \cdot cos(\theta) \\ y = b \cdot sin(\theta)$

Where $a$ is the length of the axis aligned with the x-axis and $b$ is the length of the axis aligned with the y-axis (I'm assuming the ellipse is oriented along the axes).

The mistake

The temptation is to assume that $\theta$ represents the angle around the ellipse, which it does if your ellipse is a circle, or when $\theta = \left\{0, \frac{\pi}{2}, \pi, \frac{3\pi}{2}\right\}$. However, in most circumstances $\theta$ does not represent an angle.

The question then is how to find the angle $\phi$, around the ellipse to point (x, y).

b a φ (x, y)

The solution

The hardest part of the problem is to realise that there is a problem. After that, it's basic trigonometry to find the solution.

$\qquad\begin{align} tan(\phi) &= \frac{y}{x} \\ tan(\phi) &= \frac{b \cdot sin(\theta)}{a \cdot cos(\theta)} \\ tan(\phi) &= \frac{b}{a} \cdot tan(\theta) \\ \phi &= atan \left(\frac{b}{a} \cdot tan(\theta)\right) \end{align}$

Likewise, you can calculate the inverse with:

$\qquad\theta = atan \left(\frac{a}{b} \cdot tan(\phi)\right)$

This is particularly useful for generating arcs in Processing.js where $\theta$ is used in the calculation for the angles to start and stop.

If you want to find a point on the ellipse which aligns with another point (px, py), and the origin (say placing a planet on an elliptic orbit based on a mouse click), it's even easier.

$\qquad\theta = atan \left(\frac{a \cdot py}{b \cdot px} \right)$

The hardest part of all this was realising that the parametric "angle" I was using to define an elliptic arc was not the angle I expected or really any sort of angle at all.