# Numerical Solutions to the Variational Problems by [PERSON]'s Path-Finding Algorithm
## 4 Ray Tracing and Snell's Law  
We first apply [PERSON]'s algorithm to describe the optical ray tracing in a medium. According to [PERSON]'s principle of least time, the trajectory of energy transfer, or the ray, of a wave from points a to b in a medium will follow the path that takes the minimum ToF. The principle can also be stated in terms of the optical path length [3],  
\[\mathrm{L}=\int_{\mathrm{a}}^{\mathrm{b}}\mathrm{n}(\mathrm{x},\mathrm{y}, \mathrm{z})\mathrm{d}\mathrm{s}, \tag{7}\]  
where n(x,y,z) is the refractive index of the medium at the position (x,y,z). The actual path is the one with the shortest L. We can show that this is also the path with minimum ToF. By definition, n = c/v, where c is the light speed in vacuum, and v = v(x,y,z) is the wave speed at the position (x,y,z) in the medium. We can rewrite Equation (7) as  
\[\mathrm{L}=\int_{\mathrm{a}}^{\mathrm{b}}\mathrm{c}\frac{\mathrm{d}\mathrm{s} }{\mathrm{v}(\mathrm{x},\mathrm{y},\mathrm{z})}=\mathrm{c}\int_{\mathrm{a}}^{ \mathrm{b}}\frac{\mathrm{d}\mathrm{s}}{\mathrm{v}(\mathrm{x},\mathrm{y}, \mathrm{z})}. \tag{8}\]  
Since c is a constant, minimizing L in Equation (8) is equivalent to minimizing the integral:  
\[\mathrm{t}_{\mathrm{f}}=\int_{\mathrm{a}}^{\mathrm{b}}\frac{\mathrm{d}\mathrm{ s}}{\mathrm{v}}, \tag{9}\]  
Obviously, t\({}_{\mathrm{f}}\) is the total ToF of the wave traveling from point a to b. The ray path with minimum optical path length is thus the path that a traveling wave takes with minimum ToF. Compared with Equation (1), t\({}_{\mathrm{f}}\) is the functional integral in which its value depends on the ray path (y(x),z(x)). Finding the actual ray path becomes a variational problem of finding the path (y(x),z(x)) that is minimized t\({}_{\mathrm{f}}\). In a homogeneous medium, n is a constant. The wave speed is constant throughout the medium. From Equation (9), minimizing t\({}_{\mathrm{f}}\) is equivalent to minimizing the Euclidian path length s = \(\int_{\mathrm{a}}^{\mathrm{b}}\mathrm{d}\mathrm{s}\) connecting points a and b. It is well known from basic geometry that the path is a straight line. Light will take a straight path through a homogeneous medium. When a wave travels through a boundary of two homogeneous mediums with different wave speeds, refraction occurs. The ray path changes its direction at the incident point. The relation between the incident angle \(\mathrm{\theta_{i}}\) and the refracted angle \(\mathrm{\theta_{r}}\), with respect to the normal line at the incident position, can be expressed as [26]  
\[\frac{\sin\mathrm{\theta_{i}}}{\sin\mathrm{\theta_{r}}}=\frac{\mathrm{v_{i}}} {\mathrm{v_{r}}}, \tag{10}\]  
where \(\mathrm{v_{i}}\) and \(\mathrm{v_{r}}\) are the wave speeds of the incident and refracted waves, respectively. For the light wave, Equation (10) can be expressed as the well-known Snell's law,  
\[\mathrm{n_{i}}\mathrm{sin\theta_{i}}=\mathrm{n_{r}}\mathrm{sin\theta_{r}} \tag{11}\]  
where \(\mathrm{n_{i}}\) and \(\mathrm{n_{r}}\) are the refractive indices of the medium of the incident and refracted waves, respectively. To trace the ray path of a refracted wave using [PERSON]'s algorithm, we first need to discretize the space into a spatial network. Since the incident ray, the refracted ray, and the normal line lie on the same plane, the problem is two-dimensional. A preliminary study of this simulation can be found in [6]. However, they used a network on a square lattice with long-range connections, which introduced large numerical errors in the calculation. As discussed in Section 2, applying the two-dimensional Moser lattice to the problem can improve the accuracy of the simulation. The next step is to define the weight of each edge. We define the weight of the edge joining vertices i and j as the ToF of a wave traveling along a straight path joining vertices i and j.