Number of possible rays in rectangular mirror room between two points

107 Views Asked by At

Question

There is a rectangular room with mirrors of $a$ width and $b$ height (Aligned with co-ordinate axes, so lower left corner is at $(0, 0)$ and upper right corner is at $(a, b)$). There are two points $A$ at $(p, q)$ and $K$ at $(x_0, y_0)$. Find the number of possible rays that start at point $A$ and reach $K$ after $0$ or more reflections.

Light ray will stop if it reaches point $A$ or $K$, so ray starting from $A$ should reach $K$ before it returns to $A$.

Also the length of ray should not exceed $d$. ($a, b, x_0, y_0, p, q, d \in \mathbb{N}$, All numbers here are natural numbers)

Image for problem

Attempt

I tried solving this problem by finding reflected image of point $K$.

The general co-ordinate of reflected image of point $K$ is $(2ma \pm x_0, 2nb\pm y_0)$ (here $n, m\in \mathbb{N}$)

So, the general equation of line from this image to $A$ is $\frac{y-q}{x-p} = \frac{(2nb \pm y_0)-q}{(2ma \pm x_0)-p}$

The length of array when it reaches $K$ is $\sqrt{((2nb \pm y_0)-q)^2+((2ma \pm x_0)-p)^2}$

So, we could distinguish rays using line slopes and find number of possible rays by substituting all values of $m, n$ such that distance is less than $d$.

I'm looking for a better or efficient way of solving this.