# Ellipse tangent to two circles

We're given two circles with radii $p$ and $q$, one centered at the origin, and one centered at the point $(w,0)$.

I want to construct an ellipse of the form $$\frac{(x-c)^2}{a^2} + \frac{y^2}{b^2} = 1$$ that is tangent to the two circles, as shown here:

If $b$ is known, can we obtain closed form expressions for $a$ and $c$ as functions of $p$, $q$, $w$ and $b$.

• Are the circles always internally tangent to the ellipse?
– amd
Apr 12, 2017 at 6:44
• Yes. Or, equivalently, the way I think of it: I'm given the circles, and I want the ellipse to go outside the circles. Apr 12, 2017 at 7:50

For ellipse $$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$$

Equation of normal at $(x_1,y_1)$:

$$a^2y_1(x-x_1)=b^2x_1(y-y_1)$$

Put $y=0$,

$$x=\frac{a^2-b^2}{a^2}x_1=e^2x_1 \tag{y_1 \ne 0}$$

which is the $x$-intercept.

Radius $p$:

\begin{align*} p^2 &= (x_1-e^2x_1)^2+y_1^2 \\ &= \frac{b^4x_1^2}{a^4}+y_1^2 \\ &= \frac{b^4x_1^2}{a^4}+b^2\left( 1-\frac{x_1^2}{a^2} \right) \\ &= b^2-\frac{b^2e^2x_1^2}{a^2} \tag{1} \end{align*}

Similarly,

$$q^2=b^2-\frac{b^2e^2x_2^2}{a^2} \tag{2}$$

$(1)-(2)$,

$$p^2-q^2=\frac{b^2e^2}{a^2}(x_2^2-x_1^2) \tag{3}$$

Also $$w=e^2(x_2-x_1) \tag{4}$$

On solving,

$$x_1=\frac{a^2(p^2-q^2)}{2b^2w}-\frac{a^2w}{2(a^2-b^2)}$$

$$x_2=\frac{a^2(p^2-q^2)}{2b^2w}+\frac{a^2w}{2(a^2-b^2)}$$

and from $(1)$,

$$a=\frac{b\sqrt{(p^2-q^2)^2+w^2 \left( \sqrt{b^2-p^2}+\sqrt{b^2-q^2} \right)^2}}{p^2-q^2}$$

Note that $$c=-e^2x_1$$

The required ellipse is

$$\frac{1}{a^2} \left[ x-\frac{w}{2}+\frac{(a^2-b^2)(p^2-q^2)}{2b^2w} \right]^2+\frac{y^2}{b^2}=1$$

provided $p,q \le b$

A good combination of $p$, $q$, $w$ and $b$:

A bad combination of $p$, $q$, $w$ and $b$:

A special combination of $p$, $q$, $w$ and $b$:

• Sorry, but what is the computed value of $a$? It seems that you’re taking that parameter of the ellipse as given.
– amd
Apr 12, 2017 at 8:41
• Thank you for your answer. Your approach is different from the one that I used, so I learned something. Have you checked that it's the same as mine. I know my code is correct, because it gives the right ellipse, but I may have made mistakes when translating into LaTeX. Apr 12, 2017 at 9:55

I figured it out myself, eventually. Code is:

    p2 = p^2
q2 = q^2
b2 = b^2

h = b2 - p2
k = b2 - q2

c = w * (h - sqrt(h*k)) / (h-k)

a2 = (h + c^2) * b2 / h

a = sqrt(a2)


In traditional notation, we first define: $$h = b^2 - p^2$$ $$k = b^2 - q^2$$ Note that $h$ and $k$ are both positive in "reasonable" configurations. Then $$c = \frac{w(h - \sqrt{hk})} { h-k}$$ $$a = \sqrt{\frac{(h + c^2)b^2 }{ h }}$$
I'll write up derivation later. Wanted to get this posted before people spent more time on it.