How to find the largest rectangle inside an ellipse [duplicate]
I have an ellipse that is defined by center, width and height. The axes of the ellipse parallel to the x and y. I want to find the largest rectangle that completely fits inside this ellipse. Is there an easy way to do this?
And sorry if my terminology is a bit off... it's been a long time since I last tackled with geometry
The naive thing is to see the ellipse as a stretched circle. We know the size of the largest rectangle that fits in a circle of radius $r$ is a square of side ${\sqrt 2}r$. If the semi-axes are $a$ and $b$ we would expect the rectangle to be ${\sqrt 2}a \times {\sqrt 2}b$.
To prove this, let us put the center at the origin. The equation of the ellipse is $\left(\frac xa\right)^2+\left(\frac yb\right)^2=1$. The area of the rectangle is $4xy,$ where $(x,y)$ is a point on the ellipse and we choose the point to maximize it. The area is then $4xb\sqrt{1-\left(\frac xa\right)^2}$. The derivative of this is $\frac {4b(a^2-2x^2)}{\sqrt{1-\left(\frac xa\right)^2}}$ which is duly zero at $x=\frac a{\sqrt 2}$, giving a side of $\sqrt 2 a$
Top right corner on the ellipse (centered on origin): $x = a \cos \theta$ and $y=b\sin\theta$
where $0\le \theta \le \frac{\pi}{2}, a=\frac{width}{2}$ and $b = \frac{height}{2}$
So area:$$A(\theta) = 4xy=4ab\sin\theta\cos\theta = 2ab\sin2\theta$$ Maximum of sin is at $2\theta=\frac{\pi}{2}$. So, we have $\theta = \frac{\pi}{4}$. Therefore the 4 corners are: $$(a\cos \frac{\pi}{4},b\sin \frac{\pi}{4}), (a\cos \frac{3\pi}{4},b\sin \frac{3\pi}{4}), (a\cos \frac{5\pi}{4},b\sin \frac{5\pi}{4}), (a\cos \frac{7\pi}{4},b\sin \frac{7\pi}{4}),$$
which are of course equal to:
$$(\frac{a\sqrt{2}}{2},\frac{b\sqrt{2}}{2}), (-\frac{a\sqrt{2}}{2},\frac{b\sqrt{2}}{2}), (-\frac{a\sqrt{2}}{2},-\frac{b\sqrt{2}}{2}), (\frac{a\sqrt{2}}{2},-\frac{b\sqrt{2}}{2}),$$
And it's area is: $a\sqrt{2}\cdot b\sqrt{2}=2ab$