# Shortest polygonal path inside a rectangle

I hope you could tell me if my reasoning is correct.

We are given two points $A$ and $B$ inside a rectangle $PQRS$. We create a path $AXYB$ such that $X$ and $Y$ lie on different sides of this rectangle. What is the minimal length of such path? How many shortest paths are there?

Given a line $\mathcal{l}$ and two points $A$ and $B$ on the same side of $\mathcal{l}$ we can construct the shortest path connecting them and touching $\mathcal{l}$ by reflecting for example $A$ in $\mathcal{l}$ (let $A'$ be the image of this reflection), connecting $A'$ and $B$, let $C$ be the point of intersection of $A'B$ with $\mathcal{l}$, and then $ACB$ is the shortest path.

Could we do something similar here?

I mean, could we find a point $X$ on one side of the rectangle connecting $A$ and $B$, and then $Y$ on another side connecting $X$ and $B$?

Does that make sense?

I really want to understand how this is done, because in the next exercise I'm asked to find the shortest path with two points inside a rectangle and three on its sides.

• Just for the record. Will the shortest path be constructed like this: We reflect $A$ in on side of $PQRS$ (the vertices go clockwise) say PQ, getting $A'$, then we link $A', \ B$ getting $X$ as the point of intersection of $PQ$ and $A'B$. If we reflected $B$ in $PQ$, the result would be the same. Then we reflect $A$ in $QR$ and get $Y$ as the point of intersection of $A''X$ and $QR$. Will $AXYB$ be the shortest then? – Don Mar 7 '14 at 16:43
• @Don I would describe simply like this - join $A$ to the reflected $B$s - you want the path to cross two lines on the rectangular grid, so pick the reflections of $B$ which make this happen. Then choose the shortest eligible line and find the actual path by reflecting it back into the original rectangle. Precisely which sides you cross will be sensitive to the initial set-up. This can also be used to prove that an alternative path is longer, but reflecting it out, showing that it is not straight, and is therefore longer than the alternative straight path. – Mark Bennet Mar 7 '14 at 16:50
• Ok. I understand the construction. We glue together 4 rectangles, but use 3 of them, put $A$ and $B$ in one of them, reflect B two times, then link $A, \ B''$ so that $AB''$ intersects the lines in two points $X$ and $Y'$. We then reflect $Y'$ in the adequate line and get the shortest $AXYB$. One last question. Will there be four such shortest paths? – Don Mar 7 '14 at 17:58
• @Don The path "down and left" turns out to be the same as the path "left and down" so this kills four of the possibilities leaving $8$. $LL, LU, UU, UR, RR, RD, DD, DL$. The paths which hit "near" corners only go one way. – Mark Bennet Mar 7 '14 at 18:21