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 (11)

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

## and on Oct. 6, 2019, 2:40 p.m.

I can’t calculate correctly according to the formula. Where is my mistake? I took an example from here

https://math.stackexchange.com/questions/433094/how-to-determine-the-arc-length-of-ellipse

a=3.05; b=2.23; Theta= 2.531419; fi=50 grad

fi=atan(b*Tan(fi)/a)=

atan(2.23/3.05 * Tan(50))=

atan(0.7311 * Tan(50))=

atan(0.7311 * 1.1917)=

atan(0.8713)=41.0659148066<>50

What's my mistake?

## Peter on Oct. 7, 2019, 8:52 p.m.

tan(50 gradians) = 1, since there are 100 gradians in a right angle. It looks like you used 50 degrees. If that's what you meant, and the "grad" is a typo, then your calculation is correct. You wouldn't expect phi to equal theta at 50 degrees.

## Henry Lamousin on Jan. 24, 2020, 3:27 p.m.

Priceless! Was trying to reverse engineer a piece of code and couldn't make sense of it until I found your explanation. Amazing what a few lines of clearly written text can do. Thanks.

## Anil on Jan. 30, 2020, 6:34 p.m.

I'm trying to figure out the Y coordinate, given the X coordinate and values for a and b (major and minor axes). Am I doing something wrong here?

x = a.cos(theta)

y = b.sin(theta)

So,

theta = acos(x/a)

y = b.sin(acos(x/a))

When I'm trying to code this, I get an error, because acos() requires values between -1 and 1; whereas x/a doesn't necessary fall into that range

## Peter on Jan. 31, 2020, 2:52 p.m.

If x is on the ellipse then x / a must in the range -1 to 1, since x will always be between -a and a. If you look at the definition of x = a.cos(theta), then you can also see that x will between between -a and a, since cos(theta) is between -1 and 1.