TITLE: Two circles inside a right angled triangle!
QUESTION [30 upvotes]: The other day I was playing with Ms Paint drawing circles here and there - I coincidentally drew a circle inside a right angled triangle which I already drew. Strangely A  problem struck to my mind and I tried solving it , but I was unable to do so. I  put forward the statement of the problem which I managed to frame myself:
Problem: The legs of a right angled triangle are of length $a$ and $b$. Two circles with equal radii  are drawn such such that they touch each other and sides of the triangle as shown in the figure. Find the radius of the circle in terms of $a$ and $b$.
Figure (of course my MS Paint one)
 
Further Scope - Is there any way to generalize this for other shapes or for any other triangle?  
-------EDIT---------------------
Now to make things interesting   : Say we have a right angled triangle which is given . Then is there a method by which we can construct those two circles with a straightedge and a compass?

REPLY [6 votes]: Alternative solution:
Recall that for any triangle $\triangle ABC$, the area of the triangle equals the product of the inradius and its semiperimeter; i.e., $|\triangle ABC| = rs$, where $s = (a+b+c)/2$.  Therefore, given legs $a, b$, $c = \sqrt{a^2+b^2}$, and $$r = \frac{2|\triangle ABC|}{a+b+c} = \frac{ab}{a+b+\sqrt{a^2+b^2}}.$$  Draw the tangent line to the two circles at their common point of tangency:  this creates a smaller similar triangle with scaling factor $\frac{b-2\rho}{b}$ where $\rho$ is the common radius of the two circles.  If $r$ is the inradius of $|\triangle ABC|$ as shown, then $$\frac{\rho}{r} = \frac{b - 2\rho}{b}.$$  Putting all of this together, we find $$\rho = \frac{br}{b+2r} = \frac{a b}{3a+b+c} = \frac{ab}{3a+b+\sqrt{a^2+b^2}}.$$  This method easily generalizes to more than two congruent circles tangent to one side:  if $n$ circles are arranged along the leg of length $b$, then it is straightforward to find that $\rho = \frac{ab}{(2n-1)a + b + \sqrt{a^2+b^2}}$.