# Check if a circle is within an ellipse

I have an ellipse centered at $(h,k)$, with semi-major axis $r_x$, semi-minor axis $r_y$, both aligned with the Cartesian plane.

How do I determine if a circle with center $(x,y)$ and radius $r$ is within the area bounded by the ellipse

• Evaluating inequalities: a point $\;(a,b)\;$ withing the circle (i.e., the disk) fulfills $\;(a-x)^2+(b-y)^2\le r^2\;$ ...now, you have to check if this is within the ellipse. It's hard to say anything more in such a general case. Feb 8, 2018 at 10:06
• The inside of ellipse is where $\left({x-h\over r_x}\right)^2+\left({y-k\over r_y}\right)^2$ is less than 1. Now write the parametric equation for your circle, maximize the said function over it, and check the maximum. If it is under 1, then you are inside. Feb 8, 2018 at 10:29
• @Ng Chung Please do not edit the question as to render comments/answers that have already been given hard to understand. Feb 8, 2018 at 10:30
• @DonAntonio, Fine, but at least keep the Latex format and also correct the bugs for major and minor axes, they were the same! Otherwise, just simply roll back. Feb 8, 2018 at 10:38
• @Ricardo, what've you tried and where did you get stucked? Please show your own efforts. Feb 8, 2018 at 10:41

Idea: doing a translation we can suppose than the circle is centered at $(0,0)$. Parametrize the equation of the ellipse:

$$x(t) = h + r_x\cos t,$$ $$y(t) = k + r_y\sin t.$$ And find the maximum and minimum of $t\mapsto x(t)^2 + y(t)^2$.

Solve for $x$ or $y$ from

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

and

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

If the point of intersection is complex due to quantity under radical sign (discriminant) being negative, then the circle is inside the ellipse.

If it is zero, the circle touches the ellipse and if posive there is intersection between them at 2 or 4 points.

• Do we have a Simple way to check this? i tried to Solve the equation, but it get a kinda big. Feb 10, 2018 at 22:12
• Groebner basis solution may be helpful when equations are not linear Feb 11, 2018 at 17:09

An ellipse and a circle are both on 2d space. the ellipse is centered at $$A$$ and the circle is centered at $$B$$ first find the vector between them $$B-A$$ call it $$D$$ Make a variable $$N$$ that is the normal of $$B-A$$

We know that the strait line from the circle to the ellipse is where the circle is closest subtract the Normal times the radius from $$D$$

Solve for the intersection of an ellipse.

In code it would look like this:

var dx = circleX-ellipseX;
var dy = circleY-ellipseY;
var d = 1/sqrt(dx*dx + dy*dy);
var nx = dx*d;
var ny = dy*d;
//Ry is ellipse height
//Rx is ellipse width
if(Ry*Ry*dx*dx + Rx*Rx*dy*dy < Rx*Rx*Ry*Ry){
score += 10;
food[0] = width+15;
}

• would be to good if this worked.. ;P Mar 9, 2021 at 15:27
• I guess you would need a case for if the distance between them was less than the radius Mar 10, 2021 at 15:50
• I just reduced the radius of the ellipse, X and Y now by the circle's radius. And just checking if the mid-point is inside the "smaller" ellipse.. works for this use-case.. maybe not for all.. Mar 10, 2021 at 19:21