Ellipse inside a circle - intersection

1. Jan 31, 2012

Andromedus

Hi everyone. I hope I've found the right place for my first post here. I have a geometry problem which I need to solve for a piece of software I'm writing, and I'm hoping someone might be able to help me.

I have a non-rotated ellipse inside a circle, as in this diagram. I know the x and y coordinates for the centres of both the circle and the ellipse, and I know the radius of the circle and the width and height (major and minor axis) of the ellipse. This is also a special case of circle-ellipse intersection, in that the edges of the ellipse just touch the inside of the circle to form two tangents, both at the same height above the x-axis.

http://andromedus.com/misc/ellipse.jpg [Broken]

What I need to find out is the y coordinate of P, the vertical point of intersection.

I have found this page: http://mathworld.wolfram.com/Circle-EllipseIntersection.html which goes some way to helping me, but unfortunately I don't know get from there to a single equation in terms of the value I need to calculate - the vertical point of intersection.

Any help is much appreciated - thanks! :)

Last edited by a moderator: May 5, 2017
2. Feb 1, 2012

morphism

If you try to solve (1) and (2) simultaneously (for y, say), what you will end up getting most of the time is a degree 4 polynomial equation. While it is possible to write down a formula for the roots, the general formula is very messy. The quartic polynomial in question is

Code (Text):
(-2*b^2*a^2+b^4+a^4)*y^4+(4*b^2*a^2*w-4*a^4*w)*y^3+(2*b^2*r^2*a^2-2*b^2*a^2*w^2+2*b^2*z^2*a^2+2*ab^2*b^2+6*a^4*w^2-2*b^4*z^2-2*b^4*r^2-2*ab^2*a^2+4*z)*y^2+(4*ab^2*a^2*w-4*b^2*r^2*a^2*w-4*b^2*z^2*a^2*w^4*a^4*w^3)*y+2*b^2*r^2*a^2*w^2+2*b^2*z^2*a^2*w^2-2*ab^2*a^2*w^2-2*ab^2*b^2*r^2-2*ab^2*b^2*z^2+2*b^4*r^2*z^2+ab^4+b^4*r^4+b^4*z^4+a^4*w^4-4*z*r^2
(according to Maple). Here I'm assuming that the circle is centered at (0,0) (we can always make this assumption and translate later) and that the ellipse is centered at (z,w). The rest of the notation is just as in the MathWorld link.

Unfortunately, Maple couldn't spit out a formula for the roots. If you have Mathematica or some other such software, you might have better luck.

3. Feb 2, 2012

Andromedus

Thanks morphism. Wow, that looks pretty nasty! I am downloading the trial of Mathematica, so I'll see if can give me the solutions to that. If it can't, then I guess I'm really stuck.

4. Feb 2, 2012

5. Feb 2, 2012

Andromedus

Thanks Filip. I've given that a try and it has produced some solutions which I will now try integrating into my code. I didn't expect this to get quite so complicated!

6. Feb 2, 2012

Filip Larsen

I was going to suggest that you perhaps could use an iterative zero finding approach like Newton-Raphson [1] on a function f defined as the radial distance (with sign) between the ellipse and the circle, but it seems that calculating the value of f(y)/f'(y) [2] is going to be just as complicated as calculating the "exact" solution directly.

Edit: seems I was a bit too quick on the trigger there. Defining f as the difference between the squares of the radial distance of the ellipse and circle simplifies the expression for f(y)/f'(y) quite a bit with common sub-expression, perhaps even enough to make it a useful alternative for you.

[1] http://en.wikipedia.org/wiki/Newton's_method[/SUB]
[2] http://www.wolframalpha.com/input/?i=f+/+(df/dy)+for+f+=+y^2+++a^2(1-(y-w)^2/b^2)+-+r^2

Last edited: Feb 2, 2012
7. Feb 2, 2012

Andromedus

Filip - I'm not quite sure what I'm looking at there - is the first result the x value of the intersect point? I'm afraid this is going a little over my head.

8. Feb 2, 2012

Filip Larsen

Thinking about it I must admit that I do not think you will be able to benefit from using Newton-Raphson in this case. I forgot that you want the ellipse to be tangent to the circle and not just to intersect it, so please just ignore my suggestion about using Newton-Raphson.

(And even if you just wanted to find the intersection, the function f as it is written in [2] in my previous post is not quite right, so that is another reason to ignore that post ).

9. Feb 2, 2012

Filip Larsen

I would like to add a few comments to the solution in post #4. The output from WolframAlpha lists several solutions. If you let the ellipse slide up the y-axis with its center on (0, w), then for small values of w there will be no intersections between the ellipse and the circle. As w increase, the ellipse will eventually for a single value w = w1 just touch the circle (as on your drawing) and there will be exactly to intersections between the circle and the ellipse. This is the first solution listed by WolframAlpha in post #4. When w is increase above w1 there will now be 4 intersections and these are the second and third solution in the output.

So, given that you have a circle of radius r and center in coordinate (0,0), and an ellipse with major axis a, minor axis b, and center at coordinate (0,w), where 0 < ba < r and 0 < w < r-b, there is exactly one value of w where the two are tangential to each other, namely when

$$w = w_1 = \sqrt{(1-b^2/a^2)(r^2-a^2)}$$

With this value of w you can then calculate, say, the positive x value of the intersection point using the first expression for x in the output and from that x-value the corresponding y value. I must admit it is a complicated expression, but it looks like it can be simplified a bit using common sub-expressions. Unfortunately I have not been able to nudge WolframAlpha into providing a nicer expression than the given one so if anyone here are able to do that then please post a link.

10. Feb 2, 2012

Andromedus

Thank you Filip for your help.

I've found a solution to this problem now which was given to me by someone on mathnerds.org, who suggested equating gradients - ie the gradient of the circle and the gradient of the ellipse are the same at the point they touch, so by differentiating and equating we ended up with a very simple expression for y, the vertical intersect point:

y = w / (1 - (b^2 / a^2))

Plugging that into my program verifies that it works.

Thanks to all for helping. :)

11. Feb 3, 2012

Filip Larsen

Nice work!

Just so I understand: is the w you use in that equation same as the w I mention in post #9? If so, you can also write the y-value for the tangential point as

$$y_t = \sqrt{\frac{r^2-a^2}{1-b^2/a^2}}$$

12. Feb 3, 2012

Andromedus

Yes, the ellipse is positioned with its centre at (0,w).

That's a nice way to express it in terms of just r, a and b. :)

13. Feb 3, 2012

morphism

Ah - I hadn't realized that your ellipses were always centered at (0,w) and that you always wanted tangency. That does simplify matters a lot.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook