Finding beam paths using reflection

I'm trying to figure this out on my own so no direct answers please - I really am looking for pointers on different ways to approach this problem.

Given some dimensions, a point A, a point B, and a maximum distance, calculate how many possible paths exist from A to B where the distance between A and B is less than or equal to the max distance. If a path intersects a "wall" it will reflect at the angle of incidence. If a path intersects a "corner" it will reflect back the way it came.

For example:

If you have a plane with dimensions 2x3, with point A at $(1,1)$ and point B at $(2,1)$ and a max distance of 4, there are 7 vectors that lead from A to B (with total path length less than or equal to max distance) either directly or by reflecting off a "wall". Examples of some of the $7$ answer vectors are $(0,1), (1,2),(1,-2),(-3,-2)$ which I have diagrammed on the sketch below. The problem is that I don't have any of this vector information, I only have the dimensions, point A and B, and the max distance - all of which are variable depending on the input.

enter image description here

Any pointers or thoughts on how to approach this problem would be appreciated.

Thanks


To expand a bit on the suggestion in my comment, you can “unfold” the paths by repeated reflections of the target point $B$ and the reflectors themselves. Each image of $B$ and, of course, $B$ itself, that lies within the maximum distance corresponds to a unique path from $A$ to $B$.

enter image description here

The trick, then, is to efficiently generate these images of $B$, but that seems fairly straightforward to do since the reflecting surfaces parallel the coordinate axes. If the right edge of the box is the line $x=w$, then the $x$-coordinate of the first reflection is $w+(w-x_B)$, the second is $2w+x_B$, the third $3w+(w-x_B)$ and so on. In general, the even-numbered reflections are spaced $2w$ apart, as are the odd-numbered reflections. This pattern holds going to the left as well. The same pattern occurs for the reflections in the top and bottom walls, except that the spacing between reflections with the same parity is $2h$, where $h$ is the height of the box. A pair of nested loops seem like they’d do the trick here.

If you need to trace any of the paths, draw a straight line from $A$ to the corresponding image of $B$. Each time this line crosses one of the grid lines in the above diagram (which are the reflections of the sides of the box), the actual path will change direction.

enter image description here

(Sorry about the near-illegible labels. Text doesn’t appear to survive GeoGebra’s graphics export process any more.)