If we ignore all dimensions of the pipe except the length, this is equivalent to minimizing the sum of the squares of the intercepts of a line passing through the point $(r,s)$ in the first quadrant. Let $a$ and $b$ be the $x$-intercept and $y$-intercept respectively. Thus, the function we wish to minimize is (the objective function):
$f(a,b)=a^2+b^2$
Now, using the two-intercept form for a line, we find we must have (the constraint):
$\displaystyle \frac{r}{a}+\frac{s}{b}=1$
Using Lagrange multipliers, we find:
$\displaystyle 2a=\lambda\left(-\frac{r}{a^2} \right)$
$\displaystyle 2b=\lambda\left(-\frac{s}{b^2} \right)$
and this implies:
$\displaystyle b=a\left(\frac{s}{r} \right)^{\frac{1}{3}}$
Substituting for $b$ into the constraint, there results:
$\displaystyle \frac{r}{a}+\frac{s}{a\left(\frac{s}{r} \right)^{\frac{1}{3}}}=1$
$\displaystyle a=r^{\frac{1}{3}}\left(r^{\frac{2}{3}}+s^{\frac{2}{3}} \right)$
Hence, we have:
$\displaystyle b=s^{\frac{1}{3}}\left(r^{\frac{2}{3}}+s^{\frac{2}{3}} \right)$
and so we find:
$\displaystyle f_{\min}=f\left(r^{\frac{1}{3}}\left(r^{\frac{2}{3}}+s^{\frac{2}{3}} \right),s^{\frac{1}{3}}\left(r^{\frac{2}{3}}+s^{ \frac{2}{3}} \right) \right)=\left(r^{\frac{2}{3}}+s^{\frac{2}{3}} \right)^3$
Now, we need to take the square root of this since the objective function is the square of the distance we actually wish to minimize. Let $\ell$ be the length of the pipe, and we now have:
$\displaystyle \ell_{\max}=\left(r^{\frac{2}{3}}+s^{\frac{2}{3}} \right)^{\frac{3}{2}}$
Letting $r=6\text{ ft}$ and $s=9\text{ ft}$ we have:
$\displaystyle \ell_{\max}=\left(6^{\frac{2}{3}}+9^{\frac{2}{3}} \right)^{\frac{3}{2}}\text{ ft}\approx21.07044713766\text{ ft}$