0
$\begingroup$

Given a rectangle of width $w$ and height $h$, what are the semi-major, minor axes of the circumscribed ellipse, i.e., such that its arc barely touches the rectangle corners, but doesn't cut through the rectangle? For example,

http://www.forkosh.com/mimetex.cgi?%5Ccompose%7B%5Ccircle(250,60)%7D%7B%5Cfbox%7B%5Cnormalsize%5Crm%20Have%20a%20nice%20day!%7D%7D

The answer doesn't seem unique, but there clearly seems to be a "best-fit".

  • 0
    Never mind... found it at http://stackoverflow.com/questions/433371/ellipse-bounding-a-rectangle (which, coincidentally, is what I'm looking to do, i.e., program it). From that answer, "get the dimensions of the bounding ellipse by just multiplying the dimensions of the rectangle by $\sqrt{2}$"2017-02-18
  • 0
    If you multiply the length of the rectangle you have shown by $\approx 1.4$ you will obtain a too wide approximating ellipse... compared to the one shown.2017-02-18
  • 0
    @JeanMarie I think we're just having a "terminology malfunction" here (which was actually a bit ambiguous in the stackoverflow discussion, too, but the correct interpretation seemed pretty straightforward). Multiply the width/height by $\sqrt{2}$ and take **half** that as the semi-major/minor axes. (Alternatively, take $\sqrt{2}\;\times$ **half** the width/height as the semi-major/minor axes.) That clears things up, right?2017-02-18

3 Answers 3

1

I would like to argue against the $\sqrt{2}$ scaling factor and propose an alternate solution.

Let us show first how the $\sqrt{2}$ scaling factor is derived, and then show that there is a better choice, obtained by a different computation ((5) instead of (3) below) as can be seen on the example of the figure given below.

Consider rectangle with vertices $(\pm x_0,\pm y_0)$ (we assume $0

Among the infinite number of ellipses circumscribed to the rectangle, let us take as esthetical criteria the proportionality rule:

$$\tag{1}\dfrac{x_0}{y_0}=\dfrac{a}{b}$$

The other constraint is that equation $\dfrac{x^2}{a^2}+\dfrac{y^2}{b^2}=1$ is verified by $x=x_0,y=y_0$, i.e.,

$$\tag{2}\dfrac{x_0^2}{a^2}+\dfrac{y_0^2}{b^2}=1.$$

Conditions (1)+(2) give a unique positive solution for $a$ and for $b$:

$$\tag{3}\begin{cases}a&=&\sqrt{2}x_0\\b&=&\sqrt{2}y_0\end{cases}$$

giving the green ellipse in the figure below.

But less elongated ellipses like the blue one or the red one are good challengers in this beauty contest.

I suggest to replace (1) by

$$\tag{4}\dfrac{x_0}{y_0}=\left(\dfrac{a}{b}\right)^2$$

(In this way, we take into account the fact that, if the rectangle is far from a square, the "stretching effect" has to be somewhat attenuated).

The formulas that one can deduce from (2) and (4) are:

$$\tag{5}\begin{cases}a&=&\sqrt{x_0(x_0+y_0)}&=&\sqrt{x_0^2(1+\frac{y_0}{x_0})}&<&\sqrt{2}x_0\\ b&=&\sqrt{y_0(x_0+y_0)}&=&\sqrt{y_0^2(1+\frac{x_0}{y_0})}&>&\sqrt{2}y_0\end{cases}$$

which would correspond to the less elongated red curve.

enter image description here

  • 0
    Thanks, JeanMarie. You're right, I like your answer better. Actually, I guess $\frac{x_0}{y_0}=\left(\frac ab\right)^n$ (for $n$ integer or not) should work. Is that where your additional ellipses came from??? I already programmed the "$\sqrt2$" solution as latex-like **\ovalbox{anything}** , and can easily add the optional parameter **\ovalbox[n]{anything}**, default **n=2**, to incorporate your generalization.2017-02-19
  • 0
    As suggested above, I programmed your solution with general $n$, and added an "answer" below illustrating several $n$'s (I started adding an edit below your answer above, but decided not to do that).2017-02-19
  • 0
    All this is very interesting. The aeshetics - in itself a subjective thing - can be harnessed by objective rules with one or more parameter(s) tuned to what is considered, at a given time, latitude and longitude as the most pleasant for the eye-brain system. I agree with you that exponent 1.5 looks a good compromise.2017-02-19
  • 0
    Thanks again, JeanMarie. That optimal $n=1.5$ probably depends on $x_0,\;y_0$, and it's likely the $n$ for minimum $\mbox{area}=\pi ab$ that most people would find best-looking. As mentioned in the "answer" below, I'll have to set that up to find $n(x_0,y_0)$ that minimizes area. What's seems somewhat funny is I'd naively think that $n(\cdot)$ would only depend on the dimensionless (aspect) ratio $x_0/y_0$. But the general-$n$ expressions for $a^2,\;b^2$ aren't reducible to functions of $x_0/y_0$ (since they're not dimensionless). So it's a bit intriguing to see if/how $n$ is.2017-02-20
  • 1
    Followup to above: $n=1$ minimizes ellipse area $\pi ab$ under JeanMarie's aspect-ratio constraint $\frac{x_0}{y_0}=\left(\frac ab\right)^n$, completely independently of $x_0,\;y_0$. (Not what I'd have guessed.)2017-02-20
1

May be I miss what is special here.

Taking

$$\dfrac{x^2}{a^2}+ \dfrac{y^2}{b^2}=1 \tag1$$

with cartesian/polar relations $$ (x,y)=r (\cos \theta, \sin \theta) \tag2 $$

$$\dfrac{1}{r^2}= \dfrac{\cos^2 \theta }{a^2}+ \dfrac{\sin ^2 \theta}{b^2} \tag3 $$

Plug in

$$ \cos \theta = \dfrac{w}{\sqrt{ h^2+w^2}} ,\, \sin \theta = \dfrac{h}{\sqrt{ h^2+w^2}} , r= {\sqrt{ h^2+w^2}}/2 ,\quad a = b \lambda, \tag4 $$

and simplify we get

$$\dfrac{x^2}{{ w^2+h^2 \lambda^2}}+ \dfrac{y^2}{ { h^2+w^2/ \lambda^2}}=\dfrac14 \tag5$$

"Circumscribing" a rectangle through four points (red) we can have many central conics, not just ellipses. Note that $\lambda^2 $ can have negative values as well for hyperbolas, when semi-minor axis can be even imaginary in general.

Conics thru 5 points

  • 0
    Thanks, Narasimham. I think you don't even need polar coords. Just plug in the points $x=\pm w/2,\;y=\pm h/2$ into your Eq(1), and let $a=b\lambda$. (**Note:** I think you're using $x=\pm h/2,\;y=\pm w/2$, which reverses/inverses $\lambda$ below.) Then Eq(1) just immediately becomes $\frac{w^2/4}{\lambda^2}+h^2/4=b^2$. So I think your Eq(5) should actually be $\frac{x^2}{w^2+h^2\lambda^2} + \frac{y^2}{w^2/\lambda^2\;+\;h^2}=4$. Or something like that. Anyway, the original "$\sqrt2$" answer does work, ie, intersects all four points, and I'm still trying to see what choice of $\lambda$ gives it.2017-02-19
  • 0
    P.S. I upvoted both answers, and tried to "check" both, but every time I check one, it unchecks the other. Doesn't look like either of you needs the "points", anyway. But email me (see my profile) if you're ever in the New York City area, and I'll buy you a beer instead.2017-02-19
1

This "answer" is just a continuation of @JeanMarie 's work above, where I've very straightforwardly generalized her Eq.(4) to $\mathbf{\frac{x_0}{y_0}=\left(\frac ab\right)^n}$, and illustrated several different $n$'s below (I'm thinking 1.5 looks a little better than her 2.0:)

For general $n$ (rather than the constant $2$), JeanMarie's Eq.(4) above just leads to

$\mathbf{ a^2 \; = \; x_0^2 \; + \; x_0^{2/n}y_0^{2-2/n} }$

$\mathbf{ b^2 \; = \; y_0^2 \; + \; y_0^{2/n}x_0^{2-2/n} }$

And I programmed this as the latex-like \ovalbox[n]{anything}, as mentioned in the comment below JeanMarie's answer. The examples below add a surrounding \fbox{anything} just to explicitly illustrate the inscribed rectangle.

http://www.forkosh.com/mimetex.cgi?%5Covalbox[0.75]%7B%5Cfbox%7B%5Crm%5Cnormalsize%20Hello,%20World!%7D%7D%20%5Chspace%7B20%7D%20n=0.75

http://www.forkosh.com/mimetex.cgi?%5Covalbox[1]%7B%5Cfbox%7B%5Crm%5Cnormalsize%20Hello,%20World!%7D%7D%20%5Chspace%7B20%7D%20n=1.0

http://www.forkosh.com/mimetex.cgi?%5Covalbox[1.5]%7B%5Cfbox%7B%5Crm%5Cnormalsize%20Hello,%20World!%7D%7D%20%5Chspace%7B20%7D%20n=1.5

http://www.forkosh.com/mimetex.cgi?%5Covalbox[2.0]%7B%5Cfbox%7B%5Crm%5Cnormalsize%20Hello,%20World!%7D%7D%20%5Chspace%7B20%7D%20n=2.0

http://www.forkosh.com/mimetex.cgi?%5Covalbox[5.0]%7B%5Cfbox%7B%5Crm%5Cnormalsize%20Hello,%20World!%7D%7D%20%5Chspace%7B20%7D%20n=5.0

I'm thinking: maybe choose the $n$ that minimizes the area of the ellipse, and make that the default. But I haven't gotten around to setting that up ( what's the chain rule, again? :).