# Ray Tracing Method of Gradient Refractive Index Medium Based on Refractive Index Step
## 3 Algorithm Verification
### Example 2  
The distribution function of refractive index field is:  
\[n=\sqrt{{n_{0}}^{2}(1~{}-~{}\alpha^{2}z^{2})} \tag{17}\]  
The distribution function of the refractive index field shown in Formula (17) is one of the typical distribution forms that can be obtained by ion diffusion technology. When \(n_{0}~{}=~{}1.5\) and \(\alpha~{}=~{}-~{}0.00049\), the refractive index distribution along the \(z\) axis is shown in Figure 4. It can be seen that in the range of 0 to 1000 mm, the refractive index changes smoothly, and the gradient of the refractive index is small. As the tracing distance increases, the refractive index changes more and more rapidly, and the refractive index decreases rapidly. The gradient of the refractive index rises sharply. The refractive index distribution is extremely uneven. Under paraxial conditions, the analytical solution of the ray equation is:  
\[\left\{ \begin{array}{lcl}x~{}=~{}x_{0}~{}+~{}\frac{P_{0}}{n_{0}\times~{} \alpha}[\arcsin(\alpha z)~{}-~{}\arcsin(\alpha z_{0})]\\ y~{}=~{}y_{0}~{}+~{}\frac{\theta_{0}}{n_{0}\times~{}\alpha}[\arcsin(\alpha z)~ {}-~{}\arcsin(\alpha z_{0})]\end{array} \right. \tag{18}\]  
When the incident point coordinate is (0, 0, 0) and the incident ray direction vector is (0, 0.0001, 0), Formula (18) can be simplified as:  
\[\left\{ \begin{array}{lcl}x~{}=~{}0\\ y~{}=~{}\frac{0.0001}{1.5\times~{}(-0.0001)}[\arcsin(-~{}0.0001z)~{}-~{}\arcsin (-~{}0.0001z_{0})]\end{array} \right. \tag{19}\]  
Figure 4: Distribution curve of the refractive index along the \(z\) axis. Figure 3: Ray tracing error example 1. When the tracing length is 2000 mm, the optical path analytical solution is:  
\[L1 = \int_{l}nds\] (20) \[= \int_{0}^{2000}n\ \times\ \sqrt{1\ +\ (\frac{0.00049}{1.5\times(- 0.00049})\ \times\ [\arcsin(-0.00049z)\ -\arcsin(-0.00049z_{0})])^{2}}dz\] \[= 2.39614158\ \times\ 10^{3}(\text{mm})\] Using the algorithm proposed in this paper to trace the gradient refractive index medium from 0 to 2000 mm, it is possible to obtain the optical path length \(L1\ =2.3961413\ \times\ 10^{3}\). The curve in Figure 5 shows the relationship between the geometric step length and the tracing distance of the two methods. The number of iterations for both of these two methods is 6821. For the traditional ray tracing method, the geometric step length is constant. For the method proposed in this paper, the geometric step length can be adjusted adaptively according to the refractive index distribution. In the first half of the tracing trajectory, the refractive index of the medium changes slower. Therefore, the geometric step size is larger. As the tracing trajectory gradually approaches 2000 mm, the refractive index of the medium changes intensify, and its geometric step size decreases rapidly to achieve higher accuracy. In Figure 6, the RTRIS represents the error between the optical path obtained by the ray tracing method based on the refractive index step and the actual optical path from 0 to 2000 mm. The RTSGS represents the error between the optical path obtained by the ray tracing method based on the geometric step and the actual optical path. Comparing the tracing errors of the two tracing methods in Figure 5, it can be found that the tracing accuracy of the ray tracing method based on the refractive index step is significantly better than that of the traditional ray tracing method based on the geometric step. When the tracing distance is 2000 mm, the cumulative error of the RTRIS is \(2.5\times 10^{-4}\) mm, and the cumulative error of the RTSGS is up to \(3.13\times 10^{-4}\) mm. Combine Figures 3-5, in the initial stage of ray tracing, due to the slow change of the refractive index of the medium, the errors of the two methods are almost equal although the geometric step length of RTSGS is relatively large. As the tracing distance gradually increases, the advantages of the RTSGS gradually become apparent. Because the refractive index of the medium changes smoothly and the geometric step of RTSGS is larger, there are fewer iterations and smaller cumulative errors.