Light always takes the shortest path _in time_ (how it knows which path is the shortest in time: at the level of quantum fields it takes _all_ paths and the one that is the fastest is realised). Also the speed of light depends on the medium it travels.
Now, hot air is less dense than cold air, resulting to less refraction (photon collides less often), so e.g in deserts you are literally seeing the light coming from the sky bent so that it seems like there is water (its just a distorted image of skies) in the sand.
All this because it is faster for light to bend and move through the hot air rather than take the direct straight path between the sky and your eyes.
This is physics under the subject of quantum electro dynamics and there is a fine popularised book (containing essential the same explanation) by Richard Feynman called “QED: the strange theory of light and matter” which I highly recommend. I’m a 3rd year PhD student in particle physics and cosmology.
Latest Answers