Fermat's principle of least action is one of the methods used to trace rays in inhomogeneous media. Its form is the same in anisotropic elastic and anelastic media, with the difference that the velocity depends on frequency in the latter case. Moreover, the ray, envelope, and energy velocities replace the group velocity because this concept has no physical meaning in anelastic media. We have first considered a lossy (anelastic) anisotropic medium and established the equivalence between Fermat's principle and Snell's law in homogeneous media. Then, we found that the different ray velocities defined in the literature were the same for stationary rays in homogeneous media, with phase and inhomogeneity angles satisfying the principle and the law. We considered an example of a transversely isotropic medium with a vertical symmetry axis and wavelike and diffusionlike properties. In the first case, the differences were negligible, which was the case of real rocks having a quality factor greater than five. Strictly, ray tracing should be based on the so-called stationary complex slowness vector to obtain correct results, although the use of homogeneous viscoelastic waves (zero inhomogeneity angle) is acceptable as an approximation for earth materials. However, from a rigorous point of view, the three velocities introduced in the literature to define the rays present discrepancies in heterogeneous media, although the differences are too small to be measured in earth materials. The findings are also valid for electromagnetic waves by virtue of the acoustic-electromagnetic analogy.