[Math] Polar equation of an ellipse given the origin coordinates and major and minor axis lengths

conic sectionspolar coordinates

I've been trying to create a polar equation that will give me all points on an ellipse with the independent variable being theta and the dependent variable being the radius, but I'm having a great deal of trouble wrapping my mind around how to accomplish such a feat.

The ellipse is going to be defined by it's origin's x and y positions, it's major axis length, and it's minor axis length. It can be assumed that in every case the major axis is perfectly vertical and the minor axis is perfectly horizontal.


Not really relevant to the answer, but just a little more background information. I am trying to program hit detection for a game that uses ellipses for the hitbox boundaries. The reason I need an equation like this is that I am going to be determining whether an object is within the hitbox by comparing the distance from the ellipse's center to a point on the object with the distance from the ellipse's center to the point along the ellipse in the direction of the point on the object.


Any feedback is appreciated.

Best Answer

Divide your major and your minor axes by $2$ to get the "major radius" and "minor radius". Call these $a$ and $b$. (A major and minor axis length don't uniquely specify an ellipse, you'll still have to decide if it's wider than long or longer than wide, so you'll have to make that choice here).

Substitute them into the usual equation of an ellipse.

$$\left(\frac{x}{a}\right)^2 + \left(\frac{y}{b}\right)^2 = 1$$

Substitute in $x = r\cos(\theta), y = r\sin(\theta)$.

$$ \begin{aligned} \left(\frac{r\cos(\theta)}{a}\right)^2 + \left(\frac{r\sin(\theta)}{b}\right)^2 &= 1\\ \frac{r^2\cos^2(\theta)}{a^2} + \frac{r^2\sin^2(\theta)}{b^2} &= 1\\ \frac{r^2\cos^2(\theta)b^2}{a^2b^2} + \frac{r^2\sin^2(\theta)a^2}{b^2a^2} &= 1\\ r^2(b^2\cos^2(\theta) + a^2\sin^2(\theta)) &= a^2b^2\\ r^2 &= \frac{a^2b^2}{b^2\cos^2(\theta) + a^2\sin^2(\theta)}\\ r &= \frac{ab}{\sqrt{b^2\cos^2(\theta) + a^2\sin^2(\theta)}}\\ \end{aligned} $$