<s>[INST] A circle inside an ellipse Consider an ellipse with semi-axes $a$ and $b$, taller than it is wide with a small circle of radius $r$ inside.  Assume the circle falls to the lowest point possible while staying inside the ellipse.
If $2r\le a-c$ then the circle and ellipse will meet at a single point at the bottom. If $2r>a-c$ the circle and ellipse will intersect at two points on the opposite side, leaving a space between the bottom of the circle and the bottom of the ellipse. For this case, given the radius of the circle and the dimensions of the ellipse how do I calculate the distance $d$ between the bottom of the circle and the bottom of the ellipse?

 [/INST] I got $$w =b - \sqrt{\frac{(b^2-a^2)(a^2-r^2)}{a^2}  }-r $$

Start with polar coordinates for the ellipse $$ \begin{pmatrix}x \\ y \end{pmatrix} = \tfrac{a b}{\sqrt{b^2-(b^2-a^2) \cos^2 \varphi}} \begin{pmatrix} \sin \varphi \\ -\cos\varphi \end{pmatrix}$$
where $(x,y)$ are the contact point coordinates relative to the center of the ellipse
The contact angle $\eta$ (see below) is found from the tangent vector of the ellipse as $$ \eta = 
\varphi - \tan^{-1} \left( \frac{ (a^2-b^2) \sin\varphi \cos\varphi}{b^2 - (b^2-a^2)\cos^2 \varphi} \right) $$

the location of the circle is found from the relationships $$\begin{aligned} r \sin \eta = s \sin \varphi \\ z+r \cos \eta = s \cos \varphi \end{aligned}$$
This is solved for $$\varphi = \frac{\pi}{2} - \tan^{-1} \left( \frac{b^2}{a} \sqrt{ \frac{a^2-r^2}{b^2 r^2-a^4} } \right) $$
and $$ z = s \cos\varphi - r \cos \eta $$
Finally, the gap is $$\boxed{w = b -z - r}$$ and with a lot of simplifications (thank you CAS) I got the answer above.
</s>