[Math] Ellipse bounding rectangle

circlesconic sectionsgeometryrectangles

I'm trying to find the ellipse that bounds a rectangle in a way that the "distance" between the rectangle and the ellipse is the same vertically and horizontally.

Here is an image to illustrate what I mean:

illustration

It's not perfectly drawn but the two "x" dimension need to be the same.

What I tried so far is:

The ellipse equation is $$\left(\frac{x}{a}\right)^2 + \left(\frac{y}{b}\right)^2 = 1$$

  • The "ellipse bounding the rectangle" constraint gives us $$\left(\frac{w}{a}\right)^2 + \left(\frac{h}{b}\right)^2 = 1$$
  • The "x dimension must be equal" constraint gives us $a-w = b-h$

So it's basically a $2$ equations system with $2$ unknowns.

But I got stuck at this point. If I do a substitution I have

  • $$a = b-h+w$$
  • $$\left(\frac{w}{b-h+w}\right)^2 + \left(\frac{y}{b}\right)^2 = 1$$

and I don't know how to solve it.

Best Answer

If you centre the rectangle on the origin, then it has vertices at $(-\frac{w}{2}, -\frac{h}{2})$, $(\frac{w}{2}, -\frac{h}{2})$, $(\frac{w}{2}, \frac{h}{2}),$ and $(-\frac{w}{2}, \frac{h}{2})$.

An ellipse centred at the origin has equation $\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1$ where $a$ is the 'horizontal' radius, and $b$ is the 'vertical' radius (here I am taking $a$, $b$ positive). Then the ellipse you are looking for must satisfy

$$a-\frac{w}{2} = b - \frac{h}{2}$$

or equivalently

$$2a - w = 2b - h.$$

If $w$ and $h$ are given, this is one equation between the two unknowns $a$ and $b$. This corresponds to the fact that there is an infinite family of ellipses which satisfies the distance condition.

You need one more piece of information to uniquely determine the ellipse. For example, if you would like the ellipse to go through the vertices of the rectangle, then we must have

$$\frac{\left(\dfrac{w}{2}\right)^2}{a^2} + \frac{\left(\dfrac{h}{2}\right)^2}{b^2} = \frac{w^2}{(2a)^2} + \frac{h^2}{(2b)^2} = 1.$$

Rearranging $b$ for $a$ in the previous equation, we obtain $b = a + \frac{1}{2}(h-w)$. Substituting into the latter equation, we see that $a$ must satisfy

$$\frac{w^2}{(2a)^2} + \frac{h^2}{(2a + h - w)^2} = 1$$

which, when rearranged, is a quartic in $a$.

Note, if $h = w$ (i.e. the rectangle is a square), then $a = b = \frac{w}{2}\sqrt{2}$ so the ellipse is a circle with radius equal to the distance between the origin and a vertex of the square (as one would expect).

Example: If $h = 1$ and $w = 2$ we obtain

$$\frac{4}{(2a)^2} + \frac{1}{(2a-1)^2} = 1$$

which becomes

$$4a^4-4a^3-4a^2+4a-1=0.$$

This only has two real roots, but the only positive one is $a = 1.2908$. From the first equation, we then see that $b = 0.7908$.

The result can be seen below (made using WolframAlpha).

enter image description here