Q:

How to calculate width and height of a 45° rotated ellipse bounded by a square?

I'm coming from a programming background so I apologies if this is blindingly simple or I misuse terms. I have an ellipse bounded by a square. For simplicity the centre of the square and ellipse is the origin (0,0) while the square is 2 width and 2 height.
The ellipse is rotated -45° or +45° (angle in image) and I can easily work this out. The ellipse touches all sides of the square, and I also know the intersection points. In the image A is the distance between the corner and the intersection while B is the length of the long section (the other points are symmetric).

What is the width and height, as described in the image, of the ellipse?

A:

Start with an ellipse with semi-axes $a\geq b$ in standard position, and intersect it with a $45^\circ$-line $x+y=s>0$, such that the two points of intersection coalesce. This is the case if $s=\sqrt{a^2+b^2}$, and for the point of tangency $(x_*,y_*)$ one obtains $x_*={a^2\over s}$, so that $s-x_*={b^2\over s}$.
In the case at hand the length $s=\sqrt{2}$ is given, and
$${A\over B}={s-x_*\over x_*}={b^2\over a^2}\ .$$
We therefore have to solve the system
$$a^2+b^2=2,\qquad {b^2\over a^2}={A\over B}$$
for $a$ and $b$. Since $A+B=2$ the result simplifies to
$$a=\sqrt{B},\quad b=\sqrt{A}\ .$$

