Answer to
old chestnut: two ladders:
Let a represent the height of the top of ladder A, and b represent the height of the top of ladder B, and let x represent the desired width of the alley. Then, the problem looks something like this (except the ladders are usually of different lengths so it is skewed a bit):
|\ /|
| \A B/ |
| \ / |
| \ / |
| \ / |
a| * |b
| /|\ |
| / | \ |
| / |h \ |
| / | \ |
|/____|____\|
<----x---->
Regardless of the distances involved, the triangle formed by ladder A, altitude a, and the ground is similar to the triangle formed by part of ladder A, altitude h, and the ground. Likewise, there are two
similar triangles involving ladder B. All four of these triangles are also
right triangles.
From the first pair of similar triangles, we can calculate the distance on the ground from altitude h to altitude b is xh/b.
From the second pair of similar triangles, we can calculate the distance on the ground from altitude h to altitude a is xh/a.
Since x is the total length on the ground, we have x = xh/b + xh/a.
We can eliminate x to get 1/h = 1/b + 1/a, or b = ah/(a - h).
We can apply the Pythagorean theorem to the large right triangles to get a2 + x2 = A2 and b2 + x2 = B2.
Subtracting these, and subsituting the expression for b found above, we get a2 - a2h2/(a-h)2 = A2 - B2.
You can multiply this out to get this quartic equation in a:
a4 - a3h + a2(B2 - A2) + ah(A2 - B2) + h2(B2 - A2) = 0
This looks like a mess, but remember that A, B, and h are usually going to be constants given in the problem. When these values are plugged in, you will get a quartic polynomial in a, which is still not very nice, but solvable. This will give multiple answers for the height of the end of ladder A. Ignore any answer which is less than the height at the crossing or more then the length of ladder A.
You can plug these roots into a2 + x2 = A2 to solve for the width of the alley.
When the values in the problem are feasible, this should give exactly one sensible answer for the width of the alley (positive and not wider than either ladder).
For the classic case where A=30, B=20, h=10, the quartic gives a root of approximately a=27.357, yielding x=12.312.