Standard ray-tracing programs do not calculate satisfactorily the reflection of LF radio waves from the ionosphere because they do not take losses into account. In lossy media, requiring the ray path to have a minimum attenuation in addition to a minimum wave interference gives a more accurate approximation to the full-wave solution. An extension of Fermat's principle, in which the complex phase refractive index is used instead of only the real part, expresses both of these criteria and leads to a corresponding extension of Snell's law or of Haselgrove's equations to calculate the ray path. Although such a path can have complex coordinates, only those with end points in real space are physically significant. An approximation, in which plane waves in the neighborhood of the receiver are assumed, solves the common ray-tracing problem of homing in on the receiver, a problem that is worse for ray tracing in complex space. Applying ray tracing in complex space to a plane wave incident on a plane stratified medium gives a result that agrees exactly with the result obtained by the phase integral method and that agrees satisfactorily with full-wave solutions above 30 kHz for all results shown.