Ladder (or Couch) Around a Corner Problem

One hallway which is 5 feet wide meets another hallway that is 3 feet wide in a right angle. What is the length of the longest ladder that can be carried horizontally around the corner? Move point D on the "x-axis." The ladder length is shown and graphed on the right. Note that the longest ladder is the SHORTEST (green-dashed) line segment--also where the curve has a MINIMUM value. You can change the width of the hallways by using the two sliders.