A geometric problem in placing two spheres in a pipe Help is needed to verify the following work. Alternate/simpler approaches are also welcome.
Two spheres (of radii = R & r where 50>R>r> 30) are to be packed inside a pipe of diameter = 100. Want to find x in terms of R & r as shown in the diagram below.

The red solid line divides the line of centers in the ratio p : q.
The line of centers divides the red solid line in the ratio m : n.
p : q = R : (r – x)
Letting p = hR and q = h(r – x) for some h ≠ 0, we have R + r = p + q = hR + h(r – x)
∴ $h = \dfrac {R + r} {R + r – x}$……………….…(1)
m : n = R : (r – x)
Letting m = kR and n = k(r – x) for some k ≠ 0, we have 100 – (R + r) = m + n = kR + k(r – x)
∴ $k = \dfrac {100 – (R + r)} {R + r – x}$…………….(2)
Also, $(r – x)^2 + n^2 = q^2$
Then, $(r – x)^2 + [k(r – x)]^2 = [h(r – x)]^2$
∴ $1 + k^2 = h^2$……………………..(3)
Putting (1) and (2) in (3), we have $(R + r – x)^2 + [100 – (R + r)]^2 = (R + r)^2$
If we let $R + r = T$, then we have $(T – x)^2 + [100 – T]^2 = T^2$ 
:
$x^2 – 2xT + (T – 100)^2 = 0$
$x = T – √[T^2 – (T – 100)^2]$ after rejecting the other root.
 A: Look at the line connecting the centers of the circles. The horizontal difference between the centers of the circles is $100-R-r$. The vertical difference is therefore $\sqrt{(R+r)^2-(100-R-r)^2}$ according to the Pythagorean theorem, since the hypothenuse is $R+r$. Using your $T=R+r$ this equals that $\sqrt{T^2-(T-100)^2}$ you have in your solution.
Now take the point where the big circle touches the red line. From that point, you go $R$ straight down, then this displacement we just calculated up along the line connecting the centers, then $r$ again straight down. At the end, you are lower than when you started, so to obtain a positive $x$ you have positive pointing down. So this whole path becomes
$$ x = R - \sqrt{(R+r)^2-(100-R-r)^2} + r = T-\sqrt{T^2-(T-100)^2} $$
This matches your final result, but I believe the computation is simpler this way.
A: Suppose the big pipe has width $L$, and $R+r \ge L$.
Let the bottom left hand corner of your diagram be $(0,0)$, then the centre of the
medium size pipe is $(L-R,R)$. 
We want the centre of the small pipe to lie on the line $(r,y)$, with $y \ge R$.
Since the two smaller pipes touch, their centres are $R+r$ apart, in other words, we have 
$(L-R-r)^2+(R-y)^2 = (R+r)^2$.
Solving for $y$ gives
$y = R \pm \sqrt{L(2(R+r)-L)}$. The only solution with $y \ge R$ is
$y = R + \sqrt{L(2(R+r)-L)}$.
In the diagram above, we have $x=r-(y-2R)$, hence
$x = r+R - \sqrt{L(2(R+r)-L)}$.
In terms of $T=R+r$, this gives
$x=T-\sqrt{L(2T-L)}$, substituting $L=100$ yields 
$x=T-10\sqrt{2T-100} = T-\sqrt{T^2-(T-100)^2}$.
