# Calculate intersection of two ellipses

I used the equations found here to calculate the intersection points of two circles:

(P3 is what I'm trying to get)

Except, now I want to do the same with two ellipses.

Calculating h is the tricky bit. With regular circles, it can be done with pythag theorem a^2 + b^2 = c^2, since we already know r0 (the radius):

h = sqrt(pow(a,2) + pow(r0,2))


With ellipses it seems much trickier. I don't know how to calculate h. There is not a single radius anymore: there is radiusX and radiusY.

Given radiusX, radiusY, and the center points (x,y) of each ellipse, how do I find the two intersecting points? (note: the ellipses are guaranteed to have two intersecting points in my specific application)

-
Should this not be a question for the Mathematics forum instead? –  Roy Dictus Jan 27 '12 at 11:40
I don't understand - are the ellipses alligned, sharing a major axis? –  missingno Jan 27 '12 at 11:40
Are the ellipse rotated? Have you considered the following equation of the ellipse sqr((cx-x)/radiusX) + sqr((cy-y)/radiusY) = 1.0 ? starting with this equation should help you find the solution right? –  BicycleDude Jan 27 '12 at 11:42
–  Roy Dictus Jan 27 '12 at 11:42

## migrated from stackoverflow.comSep 17 '12 at 12:17

This question came from our site for professional and enthusiast programmers.

Two ellipses can intersect in up to $4$ points. The system of two equations in two variables is equivalent to solving one polynomial of degree $4$ in one variable. In your case it is known that two of the solutions of this polynomial are real, but this does not simplify anything algebraically except for a few cases where there is some special geometric relationship between the ellipses. An exact solution in terms of the equations defining the ellipses will have the same complicated zoo of nested radicals as the formula for solving a general quartic equation. Unless for some unusual reason you really need the infinite-precision algebraic answer, it is simpler to solve numerically for the two intersection points.

-
This is pretty much the answer I was coming back to make. Years ago I know someone who worked out a general solution - it was full of special cases and I think had to deal with 2, 3, 4 intersection points separately. If this is to solve a practical problem you are better off using a numeric technique to home in on the solutions. –  half-integer fan Mar 6 at 22:41

Let your ellipses has their foci on X-axis. Then calculate points of intersection of both ellipses by solving the system:

x^2/a1 + y^2/b1 = 1


and

x^2/a2 + y^2/b2 = 1


h will be a Y and -Y of this two point of solution.

-
(b^2, 0, 0)