18: Using some convenient triangles
one gets the formula
Note that this tells us how long a beam can fit at a specific angle, but this does not guaranteee that this beam will fit at different angles. Thus, if we want to carry this beam completely through the bend, we need a length that will fit in all position. This means that the optimal length is actually the minimal of the lengths that we calculated above.
Thus one needs to minimize