Need assistance on geometry problem 
Having a really hard time solving this problem. Given:


*

*a circle of radius $a$

*an ellipse with minor axis $g$ and major axis $f$

*the ellipse is oriented so that the major axis is parallel with the vector between the circle and ellipse

*lines which are tangent to both the ellipse and the circle while crossing between them 

*$d_1$ is the distance from the center of the circle to the crossing point

*$d_2$ is the distance from the center of the ellipse to the crossing point

*$d_3$ is the horizontal distance from the ellipse tangent to the crossing point

*$d_4$ is the distance from the center of the circle to the center of the ellipse

*$d_5$ is the horizontal distance from the center of the ellipse to the ellipse tangent

*$b$ is the vertical distance to the ellipse tangent

*$L$ is the distance from the crossing point to the ellipse tangent

*I have determined the following relationships


*

*$\sin(\theta_1) = \frac{a}{d_1}$

*$\sin(\theta_2) = \frac{b}{L}$

*$\theta_1$ = $\theta_2$

*$L = \sqrt{d_3^2 + b^2}$

*$d_4 = d_1 + d_2$

*$d_2 = d_3 + d_5$

*$\frac{b^2}{g^2} + \frac{d_5^2}{f^2} = 1$

*$\tan(\theta_1) = \frac{b}{d_3}$



To clarify, the known values are:


*

*$a$

*$g$

*$f$

*$d_4$


I would like to solve for $d_2$. Any assistance would be greatly appreciated.

Here's a coordinate-based approach.

Set the center of the circle at the origin. Then the tangent line through $T(a \cos\phi, a \sin\phi)$ has $x$- and $y$-intercepts $a\sec\phi$ and $a\csc\phi$, respectively. (Note that the $x$-intercept is $d_1$ in your figure.) In intercept-intercept form, the line's equation is
$$\frac{x}{a\sec\phi} + \frac{y}{a\csc\phi}=1 \qquad \text{or, more simply,} \qquad x \cos\phi + y\sin\phi = a$$
We can determine the intersections of the line with the ellipse
$$\frac{(x-d_4)^2}{f^2}+\frac{y^2}{g^2}=1$$
by replacing $y$ with $(a - x \cos\phi)/\sin\phi$. This gives
$$\begin{align}0 &= x^2 ( f^2 \cos^2\phi + g^2 \sin^2\phi ) - 2 x ( a f^2 \cos\phi + d_4 g^2 \sin^2\phi ) &(\star)\\
&\quad+ a^2 f^2 + d_4^2 g^2 \sin^2\phi - f^2 g^2 \sin^2\phi
\end{align}$$
Because (for $\phi$ corresponding to a line that is tangent to the ellipse) the line should have just one intersection with the ellipse, we know that $(\star)$ must have only one root, $x$; thus, its discriminant must vanish:
$$-4 f^2 g^2 \sin^2\phi \; ( ( d_4^2 - f^2 + g^2 ) \cos^2\phi - 2 a d_4 \cos\phi + a^2 - g^2  ) = 0 \quad (\star\star)$$
Presumably, $f$ and $g$ are non-zero. If $\sin\phi = 0$, then our common tangent line is vertical; this requires that the ellipse be tangent to the circle, so that $d_2 = f$. In general, we must have that the final factor of $(\star\star)$ vanishes; we can solve this quadratic for $\cos\phi$:
$$\cos\phi = \frac{a d_4 \pm \sqrt{a^2 d_4^2 - (d_4^2-f^2+g^2)(a^2-g^2)}}{d_4^2-f^2+g^2} \qquad (\star\star\star)$$
Recall that $d_1 = a\sec\phi = a/\cos\phi$. From $(\star\star\star)$, we have
$$\begin{align}
d_1 &= \frac{a(d_4^2-f^2+g^2)}{a d_4 \pm \sqrt{a^2 d_4^2 - (d_4^2-f^2+g^2)(a^2-g^2)}} \\
&= \frac{a(d_4^2-f^2+g^2)(a d_4 \mp \sqrt{a^2 d_4^2 - (d_4^2-f^2+g^2)(a^2-g^2)}}{a^2 d_4^2 - \left(a^2 d_4^2 - (d_4^2-f^2+g^2)(a^2-g^2)\right)} \\
&= \frac{a(a d_4 \mp \sqrt{a^2 d_4^2 - (d_4^2-f^2+g^2)(a^2-g^2)}}{a^2-g^2}
\end{align}$$
and then
$$\begin{align}
d_2 = d_4 - d_1 = \frac{-g^2 d_4 \pm a\sqrt{a^2 d_4^2 - (d_4^2-f^2+g^2)(a^2-g^2)}}{a^2-g^2}
\end{align}$$
Some notes:


*

*The "$\pm$" ambiguity accounts for the fact that there are four tangent lines (corresponding to two values of $\cos\phi$) common to the circle and ellipse. The "internal" pair cross between the centers; the "external" pair enclose the circle and ellipse. (The external pair may be parallel. Specifically, the external pair is parallel when $g=a$, which is why the formula for $d_2$ seems averse to this situation: if the lines are parallel, $d_2$ is infinite.)

*When $d_4 = a + f$ (the circle and ellipse are tangent, and the tangent line is vertical), the above formula (with $\pm=+$) reduces to $d_2 = f$. So, the formula incorporates the $\sin\phi = 0$ case from before.

*When the ellipse is a circle of radius $b$ (not the $b$ in your figure) ---that is, when $f = g = b$--- then the formula (with $\pm=+$) reduces to $d_2 = \frac{d_4 b}{a+b}$. (Correspondingly, $d_1 = \frac{d_4 a}{a+b}$.) It's left to the reader to verify that this is consistent with the figure.

*When the ellipse is a circle congruent to the given circle ---that is, when $f = g = a$--- the formula in the previous bullet reduces to $d_2 = d_4/2$. (It's problematic to directly substitute $f=a$ and $g=a$ into the $d_2$ formula.) This is clearly consistent with the figure.

