Problem:
A fence q feet tall runs parallel to a building at a distance of p feet from the building. What is the length of the shortest ladder that can reach from the ground over the fence to the wall of the building?


Visualization:

Below you can experiment with different values of p, q and with different ladders. To see if the ladder can be used to reach the building, press Play. You can also find the shortest ladder ( for the given p and q ) that will reach the wall ( just click on Optimize ).

Now let's try to solve this problem.

On the picture above you can see a ladder reaching from the ground ( point A ) to the wall ( point D ). The ladder touches the fence ( point B ), so clearly it is the shortest ladder that can reach to the wall from A. Let us express the length of this ladder in terms of a. Using Pythagorean Theorem we have

|AD|2=|OA|2+|OD|2

It's easy to see that

\begin{displaymath}\vert OA\vert=p+a\qquad\mbox{ and }\qquad \vert OD\vert=q+\vert ED\vert
\end{displaymath}

In order to find the length |ED| we can use the similarity of triangles $\Delta ABC$ and $\Delta BDE$.

\begin{displaymath}\frac{\vert ED\vert}{\vert CB\vert}=\frac{\vert EB\vert}{\vert CA\vert}
\end{displaymath}


\begin{displaymath}\frac{\vert ED\vert}{q}=\frac{p}{a}
\end{displaymath}

So finally:

\begin{displaymath}l(a)=\vert AD\vert=\sqrt{\left(q+\frac{pq}{a}\right)^2+(p+a)^2}
\end{displaymath}

Now we can find the minimum of l(a) for a>0 ( that will give us the shortest ladder ). In order to simplify computations we will find the minimum of

\begin{displaymath}\phi(a)=\left(q+\frac{pq}{a}\right)^2+(p+a)^2
\end{displaymath}

We have

\begin{displaymath}\phi^\prime(a)=2\left(q+\frac{pq}{a}\right)\cdot\left(-\frac{pq}{a^2}\right)
+2(p+a)
=2(a+p)\left(1-\frac{pq^2}{a^3}\right)
\end{displaymath}

So

\begin{displaymath}\phi^\prime(a)=0\quad\iff\quad \frac{pq^2}{a^3}=1
\end{displaymath}


a0=p1/3q2/3

If a<p1/3q2/3, then a3<pq2 and $\phi^\prime(a)<0$. If in turn a>p1/3q2/3, then a3>pq2 and $\phi^\prime(a)>0$. Thus it is clear that $\phi$ has a minimum at a0 and of course

\begin{displaymath}l(a)=\sqrt{\phi(a)}
\end{displaymath}

has a minimum at a0 too. We can now obtain the length of the shortest ladder by plugging a0 into l(a):

\begin{displaymath}l(a_0)=\sqrt{\left(q+p^{2/3}q^{1/3}\right)^2+\left(p+p^{1/3}q^{2/3}\right)^2}
\end{displaymath}

This page including the Java applet was written by Marek Szapiel.