6
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ You can find a wide variety of equations for ellipses, including one that fits your description, at en.wikipedia.org/wiki/Ellipse. $\endgroup$
    – amd
    Commented Jan 11, 2016 at 7:55
  • $\begingroup$ I found that answers to Ellipse in polar coordinates particularly helpful, some of it may apply here as well. $\endgroup$
    – uhoh
    Commented May 16, 2020 at 15:30

5 Answers 5

8
$\begingroup$

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} $$

$\endgroup$
1
  • 1
    $\begingroup$ @AhmedS.Attaalla: Thank you -- I can't imagine why I thought that was right. $\endgroup$
    – Eli Rose
    Commented Jan 11, 2016 at 4:18
3
$\begingroup$

The right way to check if a point is inside or outside the ellipse is to compute

$$\frac{(x-x_c)^2}{a^2}+\frac{(y-y_c)^2}{b^2}-1$$ and test the sign: negative inside, positive outside.

Polar coordinates aren't really helpful.

$\endgroup$
3
  • $\begingroup$ OP prefers to avoid rectangular plot for full domain/range but inside a restricted polar sector area of hitbox as explained in the third paragraph. $\endgroup$
    – Narasimham
    Commented Jan 11, 2016 at 11:27
  • $\begingroup$ @Narasimham: this is not an answer giving the polar equation but feedback as requested by the OP. I don't think polar coordinates is the right way. $\endgroup$
    – user65203
    Commented Jan 11, 2016 at 11:29
  • 2
    $\begingroup$ @YvesDaoust I was actually able to successfully create code to determine whether or not the point was in the ellipse with both polar coordinates and rectangular coordinates. I'm going to use the rectangular method for my project as it proved to be much simpler. Thank you for the insight. $\endgroup$ Commented Jan 11, 2016 at 15:54
1
$\begingroup$

I write the ellipse polar form formula in this link https://www.desmos.com/calculator/gkijxayubk. The independent variable is theta and the dependent variable is r. Where a and b are semi major and semi minor, (r_o, theta_o) is the ellipse center location's polar coordinate, and k*pi is the rotation angle about its center. I also publish the curve fitting of raw data resemble an ellipse shape in this link https://doi.org/10.3390/f14061102

The formula is in the attached picture. the polar formula of an ellipse

$\endgroup$
0
$\begingroup$

The equation for an ellipse entered at $(h,k)$ is:

$$(\frac{x-h}{a})^2+(\frac{y-k}{b})^2=1$$

Now note this holds where $r$ is the distance from a point to the origin:

$x=r\cos(\theta)$

And likewise

$y=r\sin(\theta)$

These two equations can be seen easily, just pick a point on the $2$ dimensional $\mathbb{R^2}$ plane, then draw the length $r$ from the origin to the point and the angle $\theta$ it makes with the $x$-axis. Then use trig to come up with equations.

Now it is just a matter of plugging in and solving for $r$ (note that the quadratic equation might be of use)

$\endgroup$
-2
$\begingroup$

HINTS:

For a start we can use standard parametric equations $ (r,\theta),(x,y) $ and then convert to Cartesian coordinates, translate by $ (h,k) $ re-convert to required polar equation $ \rho = f( \gamma ). $

$$ r= p/ (1- \epsilon \cos \theta) ; x= r \cos\theta + h ; y= r \sin \theta +k ; \rho^2 = x^2 + y^2 ; \gamma = \tan^{-1} {\frac{y}{x}}; $$

There are two ellipse tangent limits for $\gamma$ limits each of constant value, two variable radius $\rho$ limits for each intermediate $\gamma$ value as shown.

Mathematica program if helpful:

ecc = 0.6; p = 1.; h = 3.; k = 2.; r[t_] = p/(1 - ecc Sin[t]);
ell = ParametricPlot[ r[t] {Cos[t], Sin[t]}, {t, 0, 2 Pi}, 
   PlotStyle -> {Thick, Magenta}];
rho[t_] = Sqrt[r[t]^2 + h^2 + k^2 + 2 r[t] ( h Cos[t] + k Sin[t])]; 
gam[t_] = ArcTan[   r [t] Cos[t] +h, r [t] Sin[t] +k ] ;
displ = ParametricPlot[ 
   rho[t] {Cos[gam[t]], Sin[gam[t]]}, {t, 0, 2 Pi}, 
   PlotStyle -> {Thick, Red}];
Show[{ell, displ}, PlotRange -> All, GridLines -> Automatic]

DisplEllipse

To find polar angle $ \gamma $ of tangential contact to radius vector, next use the condition

$$ \frac{d \gamma}{d \rho} =0 $$

and then proceed radial transversal intersection limits...

(If you want to locate target area of displaced ellipses, calculation with pole/polar of ellipse is perhaps best, but it is not mentioned here).

$\endgroup$
4
  • $\begingroup$ Can't make any sense of this text. $\endgroup$
    – user65203
    Commented Jan 11, 2016 at 9:41
  • $\begingroup$ Any clearer with the update? $\endgroup$
    – Narasimham
    Commented Jan 11, 2016 at 11:17
  • 1
    $\begingroup$ This is a little clearer (at least you defined $\gamma$) but the final answer still doesn't stand out. Fragments like "proceed radial transversal intersection limits" are meaningless. $\endgroup$
    – user65203
    Commented Jan 11, 2016 at 11:24
  • $\begingroup$ I left it to him to take it further along the preferred polar route he passionately indicated in the title and third para. $\endgroup$
    – Narasimham
    Commented Jan 11, 2016 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .