Derivation of the fraunhofer diffraction formula Re the derivation in this PDF (Section 14.5: Single-slit diffraction, page 13).
My question is: how do we know that the wave orginating from the point at the top of the slit and the wave orginating from the middle one are exactly $\pi$ out of phase ?
Besides, is there a better mathematical formulation of this? Since I think the division of the points in halves is quite arbitrary, the same argument may apply with abitrary number of parts.
 A: Let's draw a diagram of the light hitting the slit and being diffracted by some angle:

The light ray at the bottom of the slit has a phase lag, $\phi$, compared with the ray at the top of the slit because it has to travel farther. Let's assume that the angle happens to be the one where the phase lag is $2\pi$.
Now let's ask what the phase lag is for a light ray coming from somewhere in the slit between the top and bottom ray:

The light ray comes from a distance $x$ measured from the top of the slit so $0\le x \le a$. It is (hopefully) obvious from the diagram that the phase lag of this light ray is:
$$ \phi(x) = 2\pi\frac{x}{a} \tag{1} $$
Now consider two light rays, one coming from the position $x$ and one coming from $x+a/2$. For example this could be the two rays you describe in the question, one from the top of the slit ($x=0$) and one from the middle ($x=a/2$), but we'll stick with the general case of any value of $x$.
The phase lag of the ray from $x$ is given by equation (1) above, and the phase lag of the ray from $x = a/2$ is given by:
$$\begin{align}
 \phi(x+a/2) &= 2\pi\frac{x+a/2}{a} \\
             &= 2\pi\left(\frac{x}{a} + \frac{a/2}{a}\right) \\
             &= 2\pi\left(\frac{x}{a} + \frac{1}{2}\right) \\
             &= 2\pi\frac{x}{a} + \pi \\
             &= \phi(x) + \pi
\end{align}$$
So what we've found is that any two rays separated by a distance $a/2$ have a phase difference of $\pi$. This answers your question as to why a ray from the top of the slit and the centre of the slit have a phase difference of $\pi$, but it's a more general result.
The importance of this result is that two waves with a phase difference of $\pi$ interfere destructively and cancel each other out. So for every ray in the range $0 \le x \le a/2$, i.e. from the top half of the slit, there is a corresponding ray at $x+a/2$, i.e. from the bottom half of the slit, that has a phase difference of $\pi$ and therefore interferes destructively.
This means that all the light being emitted at the angle I've drawn interferes destructively and the total intensity is zero. This angle, i.e. the angle where the phase lag across the whole slit is $2\pi$, corresponds to a dark region in the diffraction pattern.
