If light rays obey to the wave equation, why can they be thought as straight lines?

Light rays are only a good way to describe light in the limit of very short wavelengths, as compared to all other length scales in the problem. This is called the geometric-optics limit, and there one can solve the Maxwell equations in what's called the eikonal approximation to obtain Fermat's Principle and thus a light-ray description of light.

The essential point of the eikonal approximation is to make an Ansatz of the form $$E(\mathbf x,t)=E_0 e^{i(\chi(\mathbf x)-\omega t)}$$ for the electric field. Here I'm ignoring the vector nature of light, and multichromatic fields, but what follows generalizes well. Other than that, the Ansatz is quite general. In these terms, the wave equation reads $$-i\nabla^2\chi+\| \nabla \chi\|^2= \frac{n^2\omega^2}{c^2}.$$ The eikonal approximation then consists of neglecting the first term. The rationale for that is that in the short-wavelength limit $\chi$ contains a term of the form $\mathbf k\cdot \mathbf x$ which makes $\nabla\chi$ very big in comparison to $\nabla^2\chi$, which measures spatial variations in the envelope and which is therefore "small".

Once you do that, you get the eikonal equation, which reads $$\| \nabla \chi\|^2= \frac{n^2\omega^2}{c^2}.$$ (By the way, this has a very interesting counterpart in classical mechanics, the Hamilton-Jacobi equation.) The trajectories of light rays can then be defined as the integral curves of the gradient $\nabla\chi$, i.e. trajectories $\mathbf r=\mathbf r(s)$, parametrized by path length, which follow $$\frac{d\mathbf r}{ds}=\frac{\nabla \chi}{n\omega/c}.$$ These trajectories are orthogonal to the wavefronts, which are surfaces of constant $\chi$, propagate in straight lines in free space, and interact with optical elements the way you'd expect them to: for all the world, they're light rays.

For some more mathematical detail, see this question. If the above is still too complicated, let me know.


I'm sure Emilio Pisanty's answer is fine, +1, but it goes a little over my head. It also appeals to specific properties of electromagnetic waves, whereas the ray approximation is much more general than that. Here's a simpler plausiblity argument that may be more at the level that the OP can understand.

If you diffract a wave through a slit of width $w$, you get a diffraction pattern with an angular width $\theta$ of order $\lambda/w$ (in radians). When $\lambda$ is small compared to $w$, $\theta$ gets small. In the limit where $\lambda/w\rightarrow0$, $\theta\rightarrow0$, and you have a ray coming through the slit. Different types of waves (water waves, sound waves, light waves, ...) will have different details relating to things like polarization, but none of that affects the above argument.

If it is so, it should obey to the wave equation and this doesn't seem to me to describe a straight line ray.

Right. A perfectly collimated, parallel wave train can never be a solution of the wave equation. However, a diffraction pattern with a very small angular width can be a solution, and if the width is small enough, it's indistinguishable from a parallel wave train.