# Largest rotated ellipse inscribed in a rectangle

Let's say I have a parametrized ellipse

$$x (t) = a \cos(t) \cos(r) - b \sin(t) \sin(r)$$

$$y (t) = a \cos(t) \sin(r) + b \sin(t) \cos(r)$$

Where $r$ is the rotation around the axis and $t \in [0,2\pi]$ the parameter. How would I find the $a$ and $b$ such as the ellipse is largest, area wise, inside a rectangle of $w$ width and $h$ height?

Thanks math gurus!

Update: Both ellipse and rectangle are centered on $(0,0)$. Rotation $r \in [0,\pi/2]$ is elevation from the $x$ axis.

• Geometrically, $r$ is rotation around what axis? And given the axis, what does the angle $r$ mean with respect to that axis? – coffeemath Jun 22 '16 at 0:38
• We are only aloud to adjust $a$, and $b$, right? Does $r$ remain constant? – Hrhm Jun 22 '16 at 1:17
• I think that talking about the parametrization is a red herring, since this is a purely geometric problem. The question is on the correctness of the intuition that the maximizing ellipse is tangent to the rectangle at the midpoints of its sides. – Lubin Jun 22 '16 at 1:53

## 1 Answer

The maxima of $x$ and $y$ when $t$ is free are

$$\hat x=\sqrt{(a\cos(r))^2+(b\sin(r))^2},\\\hat y=\sqrt{(a\sin(r))^2+(b\cos(r))^2}.$$

We need to express that they equal $w$ and $h$, and solve for $a$ and $b$, then maximize the product.

Squaring and adding/subtracting, we get

$$a^2+b^2=w^2+h^2,\\(a^2-b^2)\cos(2r)=w^2-h^2$$ and finally, subtracting the squares

$$4a^2b^2=(w^2+h^2)^2-\left(\frac{w^2-h^2}{\cos(2r)}\right)^2,$$ which is maximum for $r=0$, the axis-aligned ellipse.

• Those are the maxima along the axes of the ellipse, not necessarily along the $x$ and $y$ axis. – Hrhm Jun 22 '16 at 13:17
• @Hrhm: I think you are wrong. Please elaborate. – Yves Daoust Jun 22 '16 at 13:22
• Yep, I'm wrong, my bad – Hrhm Jun 22 '16 at 13:32
• I am sorry, I don't get it, you skipped too many steps for my little head. Could you please add a bit more details? e.g. how did you get the x and y maxima for starters ? – jldupont Jun 22 '16 at 23:57
• @jldupont: use $p\cos(t)+q\sin(t)=\sqrt{p^2+q^2}\cos(t-\phi)$ to get the extrema. The rest is routine work. – Yves Daoust Jun 23 '16 at 6:28