When is the angle around an ellipse, not the around around the 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).

## 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.

## Comments (6)

## Philip on Jan. 23, 2018, 11:07 p.m.

Hi! Thanks for the hint : ) ) I spent 30 minutes trying to understand why by using theta angle I couldn't find the right dot on the ellipse, I knew I was doing something wrong .. and after googling I immediately found your post and solved the problem immidiately.. Thank you for sharing in your blog!

## Wade on May 16, 2018, 8:16 p.m.

Can this help to impose the initial nodal points such that the equal arclength between two points on ellipse? If yes, then Given the arclength how to compute the corresponding angle?

## Peter on May 17, 2018, 7:58 p.m.

Hi Wade,

It's possible this would help. I expect using a parametric equation for the ellipse would be the way forward. However, calculating the arc length for an ellipse is difficult - there is no closed form. Have a look at this question and answer for a bit more information: https://math.stackexchange.com/questions/433094/how-to-determine-the-arc-length-of-ellipse

## Chan on Feb. 2, 2019, 3:29 p.m.

Thanks this was really useful. Open CV works the same way (uses theta as a parameter).

For a rotated ellipse, there's one more detail. If psi is the rotation angle:

tan(phi + psi) = (y - yc) / (x - xc), and

phi = atan[(y-yc)/(x-xc)] - psi

Now you can calculate theta like before.

## Yi-Hung on April 8, 2019, 9:23 a.m.

The symbols a and b of the semi-axes in the diagram need to be switched to match your equations.

## Peter on April 8, 2019, 1:59 p.m.

Fixed, thanks!