## 06-11-2013 A Better Ellipse

I have been bothered by a particular equation for a very long time. It is the commonly provided equation for an ellipse, and is usually defined as follows:

_{1})

^{2}

a

_{1})

^{2}

b

Where the center of the ellipse is located at the point (x_{1},
y_{1}), with its x radius equal to a and its y radius equal to b.
This is all well and good as far as it goes; my dislike for it lies in the fact
that the only ellipses it can be used for are those with a length that is parallel
to either the x or y axis of the graph. If you want to plot one that lies on
a different angle, then this will not work.

There is however another way to define an ellipse that is not subject to that restriction. It can be done using the relationship between an ellipse's border and its focal points:

The sum of the distances between the focal points of an ellipse and any point on its border is a fixed constant.

This means that if we take any two points - we'll call them (a, b) and (c, d), and set a fixed value for the sum of the two line segments' length (we'll call that e), then we can define any ellipse as follows:

√[(x - a)^{2}+ (y - b)

^{2}] + √[(x - c)

^{2}+ (y - d)

^{2}] = e

That in itself is fairly simple. The real difficulty is in solving that equation for y, giving us a usable function to work with. This is a problem that I have tried on and off many times throughout the years, and inevitably failed. The trouble isn't in the math itself, but in the sheer volume of it. To solve this, all you need to do is get rid of the radicals by separating and squaring them, then expand the equation out to simple terms, regroup them, and then factor "y" out of the resulting equation. To get rid of the radicals though, you have to square some terms repeatedly, giving you a significant quantity of terms to manage.

I've probably tried to solve that about a dozen times over the years, and always gave up when doing the expansion. I finally cracked it this week when switching from working on paper to working on the computer. I initially expected it to add to the work, but found that once I got used to it, that wasn't the case. It also became much easier to re-check and make corrections, and having an infinite canvas to work on is great.

So after several more failed attempts over the past two weeks, I'm very happy to present this solution worked out from the basic equation given above.

We can begin with removing the radicals by separating and squaring them:

^{2}+ (y - b)

^{2}] + √[(x - c)

^{2}+ (y - d)

^{2}] = e

√[(x - a)

^{2}+ (y - b)

^{2}] = e - √[(x - c)

^{2}+ (y - d)

^{2}]

(x - a)

^{2}+ (y - b)

^{2}= e

^{2}- 2 e √[(x - c)

^{2}+ (y - d)

^{2}] + (x - c)

^{2}+ (y - d)

^{2}

(x - a)

^{2}+ (y - b)

^{2}- e

^{2}- (x - c)

^{2}- (y - d)

^{2}= - 2 e √[(x - c)

^{2}+ (y - d)

^{2}]

[(x - a)

^{2}+ (y - b)

^{2}- e

^{2}- (x - c)

^{2}- (y - d)

^{2}]

^{2}= 4 e

^{2}[(x - c)

^{2}+ (y - d)

^{2}]

With all of the radicals removed, we now expand.

^{2}- 2 a x + a

^{2}+ y

^{2}- 2 b y + b

^{2}- e

^{2}- x

^{2}+ 2 c x - c

^{2}- y

^{2}+ 2 y d - d

^{2})

^{2}= 4 e

^{2}(x - c)

^{2}- 4 e

^{2}(y - d)

^{2}

( - 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 y d - d

^{2})

^{2}= 4 e

^{2}(x

^{2}- 2 c x + c

^{2}) - 4 e

^{2}(y

^{2}- 2 d y + d

^{2})

- 2 a x (- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

+ a

^{2}(- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

- 2 b y (- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

+ b

^{2}(- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

- e

^{2}(- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

+ 2 c x (- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

- c

^{2}(- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

+ 2 y d (- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

- d

^{2}(- 2 a x + a

^{2}- 2 b y + b

^{2}- e

^{2}+ 2 c x - c

^{2}+ 2 d y - d

^{2})

= 4 e

^{2}(x

^{2}- 2 c x + c

^{2}) + 4 e

^{2}(y

^{2}- 2 d y + d

^{2})

+ 4 a

^{2}x

^{2}- 2 a

^{3}x + 4 a b x y - 2 a b

^{2}x + 2 a e

^{2}x - 4 a c x

^{2}+ 2 a c

^{2}x - 4 a d x y + 2 a d

^{2}x

+ 4 a b x y - 2 a

^{2}b y + 4 b

^{2}y^y - 2 b

^{3}y + 2 b e

^{2}y - 4 b c x y + 2 b c

^{2}y - 4 b d y

^{2}+ 2 b d

^{2}y

- 4 a c x

^{2}+ 2 a

^{2}c x - 4 b c x y + 2 b

^{2}c x - 2 c e

^{2}x + 4 c

^{2}x

^{2}- 2 c

^{3}x + 4 c d x y - 2 c d

^{2}x

- 4 a d x y + 2 a

^{2}d y - 4 b d y

^{2}+ 2 b

^{2}d y - 2 d e

^{2}y + 4 c d x y - 2 c

^{2}d y + 4 d

^{2}y

^{2}- 2 d

^{3}y

- 2 a

^{3}x + a

^{4}- 2 a

^{2}b y + a

^{2}b

^{2}- a

^{2}e

^{2}+ 2 a

^{2}c x - a

^{2}c

^{2}+ 2 a

^{2}d y - a

^{2}d

^{2}

- 2 a b

^{2}x + a

^{2}b

^{2}- 2 b

^{3}y + b

^{4}- b

^{2}e

^{2}+ 2 b

^{2}c x - b

^{2}c

^{2}+ 2 b

^{2}d y - b

^{2}d

^{2}

+ 2 a c

^{2}x - a

^{2}c

^{2}+ 2 b c

^{2}y - b

^{2}c

^{2}+ c

^{2}e

^{2}- 2 c

^{3}x + c

^{4}- 2 c

^{2}d y + c

^{2}d

^{2}

+ 2 a d

^{2}x - a

^{2}d

^{2}+ 2 b d

^{2}y - b

^{2}d

^{2}+ d

^{2}e

^{2}- 2 c d

^{2}x + c

^{2}d

^{2}- 2 d

^{3}y + d

^{4}

+ 2 a e

^{2}x - a

^{2}e

^{2}+ 2 b e

^{2}y - b

^{2}e

^{2}+ e

^{4}- 2 c e

^{2}x + c

^{2}e

^{2}- 2 d e

^{2}y + d

^{2}e

^{2}

= 4 e

^{2}x

^{2}- 8 c e

^{2}x + 4 c

^{2}e

^{2}+ 4 e

^{2}y

^{2}- 8 d e

^{2}y + 4 d

^{2}e

^{2}

Now we can simplify by grouping like terms, factoring, etc. and separate y from the rest of the equation.

^{2}x

^{2}- 8 a c x

^{2}+ 4 c

^{2}x

^{2}- 4 e

^{2}x

^{2}

+ 4 b

^{2}y

^{2}- 8 b d y

^{2}+ 4 d

^{2}y

^{2}- 4 e

^{2}y

^{2}

+ 4 a

^{2}c x - 4 a

^{3}x - 4 a b

^{2}x + 4 a c

^{2}x + 4 a d

^{2}x + 4 a e

^{2}x + 4 b

^{2}c x - 4 c

^{3}x - 4 c d

^{2}x + 4 c e

^{2}x

- 4 a

^{2}b y + 4 a

^{2}d y + 4 b

^{2}d y - 4 b

^{3}y + 4 b c

^{2}y + 4 b d

^{2}y + 4 b e

^{2}y - 4 c

^{2}d y - 4 d

^{3}y + 4 d e

^{2}y

+ 8 a b x y - 8 a d x y - 8 b c x y + 8 c d x y

+ a

^{4}+ b

^{4}+ c

^{4}+ d

^{4}+ e

^{4}+ 2 a

^{2}b

^{2}- 2 a

^{2}c

^{2}- 2 a

^{2}d

^{2}- 2 a

^{2}e

^{2}- 2 b

^{2}c

^{2}- 2 b

^{2}d

^{2}- 2 b

^{2}e

^{2}+ 2 c

^{2}d

^{2}+ 2 c

^{2}e

^{2}+ 2 d

^{2}e

^{2}

- 4 c

^{2}e

^{2}- 4 d

^{2}e

^{2}

= 0

+ 4 x

^{2}(a

^{2}- 2 a c + c

^{2}- e

^{2})

+ 4 y

^{2}(b

^{2}- 2 b d + d

^{2}- e

^{2})

+ 4 x(a

^{2}c - a

^{3}- a b

^{2}+ a c

^{2}+ a d

^{2}+ a e

^{2}+ b

^{2}c - c

^{3}- c d

^{2}+ c e

^{2})

- 4 y(a

^{2}b - a

^{2}d - b

^{2}d + b

^{3}- b c

^{2}- b d

^{2}- b e

^{2}+ c

^{2}d + d

^{3}- d e

^{2})

+ 8 x y (a b - a d - b c + c d)

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}

- 4 e

^{2}( c

^{2}+ d

^{2})

= 0

+ 4 x

^{2}((a - c)

^{2}- e

^{2})

+ 4 y

^{2}((b - d)

^{2}- e

^{2})

+ 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c))

- 4 y((b - d) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) - e

^{2}(b + d))

+ 8 x y (a - c)(b - d)

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}- 4 e

^{2}( c

^{2}+ d

^{2})

= 0

+ 4 x

^{2}((a - c)

^{2}- e

^{2})

+ 4 y

^{2}((b - d)

^{2}- e

^{2})

+ 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c))

- 4 y((b - d) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) - e

^{2}(b + d) - 2 x (a - c)(b - d))

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}- 4 e

^{2}( c

^{2}+ d

^{2})

= 0

+ 4 x

^{2}((a - c)

^{2}- e

^{2})

+ 4 y

^{2}((b - d)

^{2}- e

^{2})

+ 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c))

- 4 y((b - d) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- 2 x (a - c)) - e

^{2}(b + d))

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}- 4 e

^{2}( c

^{2}+ d

^{2})

= 0

We now have y separated in such a way that we can solve it as a quadratic equation, which we can do as follows:

u ≡ 4 ((b - d)

^{2}- e

^{2})

v ≡ - 4 ((b - d) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- 2 x (a - c)) - e

^{2}(b + d))

w ≡ 4 x

^{2}((a - c)

^{2}- e

^{2}) + 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c)) + (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}- 4 e

^{2}( c

^{2}+ d

^{2})

Then:

u y

^{2}+ v y + w = 0

And so:

^{2}- 4 u w)

^{2}+ b

^{2}- c

^{2}- d

^{2}

- 2 x (a - c)

^{2}(b + d)

^{2}+ b

^{2}- c

^{2}- d

^{2}

- 2 x (a - c)

^{2}(b + d)

^{2}

^{2}- e

^{2})]

^{2}((a - c)

^{2}- e

^{2})

+ 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c))

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}

- 4 e

^{2}( c

^{2}+ d

^{2})

^{1/2}

^{2}- e

^{2})]

^{2}+ b

^{2}- c

^{2}- d

^{2}

- 2 x (a - c)

^{2}(b + d)

^{2}+ b

^{2}- c

^{2}- d

^{2}

- 2 x (a - c)

^{2}(b + d)

^{2}

^{2}- e

^{2})

^{2}((a - c)

^{2}- e

^{2})

+ 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c))

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}

- 4 e

^{2}( c

^{2}+ d

^{2})

^{1/2}

^{2}- e

^{2})

^{2}+ b

^{2}- c

^{2}- d

^{2}

- 2 x (a - c)

^{2}(b + d)

^{2}+ b

^{2}- c

^{2}- d

^{2}

- 2 x (a - c)

^{2}(b + d)

^{2}

^{2}- e

^{2})

^{2}((a - c)

^{2}- e

^{2})

+ 4 x((c - a) (a

^{2}+ b

^{2}- c

^{2}- d

^{2}) + e

^{2}(a + c))

+ (a

^{2}+ b

^{2}- c

^{2}- d

^{2}- e

^{2})

^{2}

- 4 e

^{2}( c

^{2}+ d

^{2})

^{1/2}

^{2}- e

^{2})

Depending on your browser, that final equation may be somewhat difficult to
read (thank-you underdeveloped HTML math notation). In lieu of that, here is
the same final result as an image:

I'm quite happy with this, but still need to work out an equation of similar complexity. What I ultimately want to do with this is to create a C function that can draw an ellipse given the focal points and the total distance ("e" in the solution above). In order to do that effectively, I'll need to know the minimum and maximum x values of the ellipse. One way to get this would be to take the contents of the radical, set them as being equal to zero, and solve for x. That then is my next objective; hopefully there will be an update soon.