How come lenses alter the path of photons? From what I know, photons are theorized particles and believed to be massless (just energy) and travel at the speed of light. How come a lens, which is an object made of atoms, can bend a light path?
I would expect the lens to heat up but not alter the paths of massless particles.  Could someone explain in simple terms?
 A: Light behaves as a wave as well as a particle, and order to understand refraction, you have to think about light as a wave. Light travels faster in some materials than others (it travels faster in air than glass, for example). When a light wave traveling through air hits glass at an angle, one side of the wave hits the glass before the other and is traveling slower than the other. This makes the wave turn the same way a car turns when the wheels on one side are going faster than the others. Similarly, when light traveling through glass leaves the glass at an angle, one side of the wave speeds up before the other.
A: Photons obey the rules of quantum electrodynamics. To explain this I will need to teach you how to use complex numbers.
A quick tutorial on complex numbers
Complex numbers are pairs of numbers $(a,b)$ which add by the obvious rule $(a, b) + (c, d) = (a + b,\; c+d)$ and multiply by the not-at-all-obvious rule $(a, b) \cdot (c, d) = (ac - bd,\; ad + bc),$ chosen so that $(0, 1) \cdot (0, 1) = (-1, 0)$ and therefore there is a "square root of -1." If you really work out how these rules interact you can find out that the algebra is the same as the 2x2 real matrix algebra $$(a, b) \leftrightarrow \begin{bmatrix}a&-b\\b&a\end{bmatrix},$$which has  can think of as a scaled rotation matrix:$$\begin{bmatrix}a&-b\\b&a\end{bmatrix} = \sqrt{a^2 + b^2} \begin{bmatrix}\cos\theta& -\sin\theta\\\sin\theta &\cos\theta\end{bmatrix}  = \sqrt{a^2 + b^2} R(\theta) \text { , for some }\theta.$$ Here $R(\theta)$ is the 2D rotation matrix by an angle of $\theta$ radians; it is a full rotation for $\theta = 2\pi$ for example.
Adding two complex numbers therefore is like the "vector sum" of the two "arrows" that point from the origin to the numbers on the complex plane $(x, y)$, whereas multiplying by a complex number both scales the complex plane out and rotates it. (More specifically, each complex number $(a, b)$ scales-and-rotates the entire plane so that the point $(1,0)$ on the $x$-axis gets mapped to $(a, b)$.)
In many ways, rotations are the simplest "wavey" things, so it's not too surprising that when we want to describe the waviness of the quantum world we turn to some sort of rotation to do it.
Complex numbers as amplitudes
The core rules of quantum electrodynamics are very simple:


*

*Each way that something can happen is represented by a complex number, called its "amplitude."

*If something can happen many different ways, you add together the different amplitudes of the different possibilities.

*If something needs multiple things to happen, then you multiply together the different amplitudes of these different possibilities.

*When you're done, the square of the scale factor of the amplitude $a^2 + b^2$ is the probability that this thing will happen.


Now you need a rule for a particular path, which in the photon's case is really easy: If the photon travels a distance $\ell$ in a time $\tau$ and has frequency $f$ then its amplitude is $\frac1\ell ~ R(2\pi f\tau).$ We will ignore the $1/\ell$ prefactor but it leads (through all of the above) to a $1/r^2$ drop in light's intensity as you go a certain distance, which keeps the flux of energy through successive spheres (which have surface area $4\pi r^2$) constant as a burst of light goes through bigger and bigger spheres. So you can imagine that this has to do with conservation of energy.
Fermat's principle as a special case
Now these rules state that if I have a detector in one medium where light goes slower and an emitter outside where light goes faster, we must consider all straight baths from the emitter to any point on the surface between them, and then from the surface to the detector. We must sum all of these up.
Let's say that the surface is the points $(x, 0)$ on the plane, the detector is at point $(0, -D)$, and the emitter is at point $(A, B)$. Each path will then have the amplitude which goes like $R(2\pi f \sqrt{(A - x)^2 + B^2}/v_\text{out})~R(2\pi f \sqrt{x^2 + D^2} / v_\text{in}),$ where $v_\text{out}$ is the speed of light outside the medium where the detector is, and $v_\text{in}$ is the speed of light inside. Since rotating twice is the same as adding the angles, we can combine these into: $$R\left(2\pi f \left[\frac{\sqrt{(A - x)^2 + B^2}}{v_\text{out}} + \frac{\sqrt{x^2 + D^2}}{v_\text{in}}\right]\right).$$That's better, but still... Yuck! Because we have to add together a lot of these! Well, we have a special trick up our sleeves. ;-)
The trick is that when you're adding up something which is rapidly spinning around in circles like this, most of the little arrows you're adding up point in all the directions of the compass, cancelling out. Therefore the only way that these amplitudes can sum up to anything big (meaning a non-negligible probability when we compute the squared scale factor!) is if the stuff on the inside isn't changing much. This usually happens when the stuff is at an extremum, either a minimum or maximum, because there's "no lower" that it can go.
Combined with our earlier expression $R(2\pi f \tau)$ this leads to a fact called Fermat's principle: light takes the path of shortest time. In fact we've seen that light takes all paths, but we're saying now that any paths which are not near a shortest-time path all cancel each other out anyway, so it doesn't matter much to the final amplitude if you insert a photon-absorber which blocks those paths completely! 
To compute an extremum path in physics, we use calculus to take a derivative of the angle above, and set it equal to 0. $$\frac{d\theta}{dx} = - \frac{A - x}{v_\text{out}\sqrt{(A - x)^2 + B^2}} + \frac{x}{v_\text{in} \sqrt{x^2 + D^2}} = 0.$$ This identifies a special point $x$ on the surface. The triangle it makes with the outside of the medium is a right triangle with height $B$ and base $A - x$ and therefore if we measure $\phi_\text{out}$ from the "normal vector" that is perpendicular to the surface we find $(A - x) / \sqrt{(A - x)^2 + B^2} = \sin\phi_\text{out}.$ Likewise we find the other term to be $\sin\phi_\text{in},$ again measuring the angle from the normal vector perpendicular to the surface. We therefore find:$$\frac{\sin\phi_\text{out}}{v_\text{out}} = \frac{\sin\phi_\text{in}}{v_\text{in}}.$$This is also called Snell's law.
In summary
In summary, lenses alter the path of photons because photons take all paths, but since their underlying physics is "wavey" different paths can "interfere." A photon will appear to take only those paths which feature lots of "constructive interference," in the sense that if we block other paths we do not diminish the intensity of light reaching our detector by very much. The paths of constructive interference are the ones where the time taken to travel along "nearby" paths is roughly the same. This leads to light usually taking the "shortest-time-path" and a couple of constructive paths immediately around it.
Because the speeds of light are different in the two different media, the shortest-time-path becomes different in the presence of a lens, and bends. It's the same as if you want to rescue someone who's drowning and is diagonal from you (relative to the shore): you don't run straight into the water and then turn at a right angle to swim along the shore; in fact it's much better to run along the beach parallel to the shore and then turn at a right angle to swim to them, and if you want to be as fast as possible you also don't run in a straight line to them immediately jumping in the water. Ideally you compromise between the latter two: you know that you can run on the beach faster than you can swim, so you ideally run in a bent line, staying on the beach for a little longer to get a little closer, before you jump into the water and start swimming.
