
# Wave Propagation, Diffraction & Gratings

> One dimension gave us superposition and standing waves. Three dimensions give us the rest of wave
> physics: a wave now has a *direction*, and directions can be added. Everything follows — two plane
> waves crossing at an angle print a fringe pattern in space; a wave squeezed through a gap fans out
> by an angle $\lambda/d$; a row of scatterers throws light into a discrete set of beams. Those three
> facts are the entire experimental toolkit of the next two courses, and the last one is how humanity
> first caught an electron behaving like a wave. A cat's whiskers, incidentally, are a diffraction
> problem: they must out-span the gap to be worth anything.

## Learning Objectives

After this lesson you will be able to:

1. Write the **three-dimensional wave equation** with the **Laplacian**, and verify by direct differentiation that the **plane wave** $\exp[i(\mathbf k\cdot\mathbf r - \omega t)]$ solves it exactly when $k = \omega/c$.
2. Interpret the **wavevector** $\mathbf k$ geometrically — direction of travel, **wavefronts** perpendicular to it, spacing $\lambda = 2\pi/k$ — and superpose two plane waves to get a **spatial fringe pattern**.
3. Apply the **Huygens–Fresnel construction**: rebuild a propagating wavefront from **secondary point sources**, and explain why a finite aperture cannot re-emit a perfectly plane wave.
4. Estimate the **diffraction angle** $\theta \sim \lambda/d$ for an aperture or source of width $d$, and use the **inverse relation** between aperture size and angular spread.
5. Derive the **grating equation** $\sin\theta_m = m\lambda/s$ for equally spaced scatterers, identify **diffraction orders**, and predict how many orders exist for a given $s/\lambda$.

---

## Intuition

In one dimension a wave has two choices: left or right. In three it has a whole sphere of them, and
the bookkeeping device for "which way" is the **wavevector** $\mathbf k$ — a vector pointing along
propagation whose length is the wavenumber $2\pi/\lambda$. Everything in this lesson is a consequence
of being allowed to *add plane waves with different $\mathbf k$*.

Add two, and where their crests coincide you get bright bands, where crest meets trough you get dark
ones — interference is no longer a pattern in time at one point but a standing pattern painted across
space. Add a continuum of them, radiating from every point of a slit, and you get diffraction:
the wave spreads into the geometric shadow, because a finite piece of a wavefront simply does not
contain the ingredients to keep marching in a perfectly straight line. Add the waves scattered by a
regular row of atoms, and almost every direction cancels — except the special ones where every
scatterer's contribution arrives in step, which come out as sharp beams at angles set by $\lambda$
and the spacing.

That last mechanism deserves flagging now: it is how X-ray crystallography reads molecules, and in
1927 it is how a nickel crystal proved that electrons have wavelengths
([P.3.2](../c03-wave-particle-duality/02-matter-as-waves.md)). Diffraction is the instrument that
detects waviness. Build it here, classically, and it is ready when matter turns out to need it.

---

## Theory

### The wave equation in three dimensions

The 1D wave equation of [P.1.1](01-waves-and-the-wave-equation.md) generalizes by replacing
$\partial^2/\partial x^2$ with the **Laplacian** $\nabla^2$, the sum of second derivatives along all
three axes. For a scalar field $\phi(\mathbf r, t)$ — a pressure in air, a component of an electric
field, later a wavefunction — propagating at speed $c$:

$$
\boxed{\;\nabla^2\phi - \frac{1}{c^2}\frac{\partial^2\phi}{\partial t^2} = 0\;},
\qquad
\nabla^2 \equiv \frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2} + \frac{\partial^2}{\partial z^2} .
$$

Equivalently $\nabla^2 = \nabla\cdot\nabla$, the divergence of the gradient, with

$$
\nabla \equiv \hat{\mathbf x}\frac{\partial}{\partial x} + \hat{\mathbf y}\frac{\partial}{\partial y} + \hat{\mathbf z}\frac{\partial}{\partial z} .
$$

Writing it as $\nabla\cdot\nabla$ is not decoration: it is what makes the plane-wave check below two
lines of vector algebra instead of nine partial derivatives. The equation is still **linear** and
still **second order in time**, so both structural lessons of P.1.1 survive intact — solutions
superpose, and initial value plus initial velocity fix the future.

### Plane-wave solutions

A **monochromatic plane wave** — one frequency, one direction — is

$$
\phi(\mathbf r, t) = \exp\!\big[i(\mathbf k\cdot\mathbf r - \omega t)\big],
\qquad
\mathbf r = x\hat{\mathbf x} + y\hat{\mathbf y} + z\hat{\mathbf z},
\qquad
\mathbf k = k_x\hat{\mathbf x} + k_y\hat{\mathbf y} + k_z\hat{\mathbf z} .
$$

**Claim:** it solves the 3D wave equation precisely when $k \equiv |\mathbf k| = \omega/c$.

*Proof.* The gradient brings down $i\mathbf k$, because $\mathbf k\cdot\mathbf r = k_xx + k_yy + k_zz$
is linear in each coordinate:

$$
\nabla \exp\big[i(\mathbf k\cdot\mathbf r - \omega t)\big]
= i\big(k_x\hat{\mathbf x} + k_y\hat{\mathbf y} + k_z\hat{\mathbf z}\big)\exp\big[i(\mathbf k\cdot\mathbf r - \omega t)\big]
= i\mathbf k\,\phi .
$$

Taking the divergence of that vector field brings down a second factor of $i\mathbf k$, dotted into
the first:

$$
\nabla^2\phi = \nabla\cdot(i\mathbf k\,\phi) = (i\mathbf k)\cdot(i\mathbf k)\,\phi
= -\big(k_x^2 + k_y^2 + k_z^2\big)\phi = -k^2\phi .
$$

The time derivative is the familiar one, $\partial_t^2\phi = -\omega^2\phi$. Substituting both:

$$
\nabla^2\phi - \frac{1}{c^2}\frac{\partial^2\phi}{\partial t^2}
= \Big({-}k^2 + \frac{\omega^2}{c^2}\Big)\phi = 0
\quad\Longleftrightarrow\quad
\boxed{\;k = \frac{\omega}{c}\;}\ \ \blacksquare
$$

Only the length $|\mathbf k| = \sqrt{k_x^2 + k_y^2 + k_z^2}$ ever meets $\omega$, so the phase
speed is $\omega/|\mathbf k|$. Build $|\mathbf k|$ from its components and compare it with the two
shortcuts that get it wrong (the demo writes the speed as $v$):

```qm-demo wavevector-magnitude-speed

```

Note what the derivation did *not* require: any relation among $k_x, k_y, k_z$ individually. **Every
direction of $\mathbf k$ works**, provided the length is $\omega/c$ — the allowed wavevectors of a
given frequency fill a sphere of radius $\omega/c$ in $\mathbf k$-space. That sphere is the reason a
single frequency can produce two-dimensional patterns at all.

Test the claim with two waves of the same $\omega$. Swing the second wavevector around at fixed
length and the pair still shares one speed; change its length and it does not:

```qm-demo wavevector-direction-superposition

```

Three readings of $\mathbf k$ worth memorizing:

- **Direction.** Surfaces of constant phase — **wavefronts** — are the planes $\mathbf k\cdot\mathbf r = \text{const}$, which are perpendicular to $\mathbf k$; hence "plane" wave. They advance along $\hat{\mathbf k}$ at the phase speed $\omega/k = c$.
- **Magnitude.** Along $\hat{\mathbf k}$ the phase advances by $2\pi$ over a distance $2\pi/k$, so $\lambda = 2\pi/k$ exactly as in 1D.
- **Components.** $k_x$ is the wavenumber *seen* along $x$: a wave travelling at angle $\theta$ to the $z$-axis has $k_z = k\cos\theta$, $k_x = k\sin\theta$, so it prints a stripe pattern along $x$ of period $2\pi/k_x = \lambda/\sin\theta$ — always *longer* than $\lambda$. This projection is the whole of the grating equation, met later in this lesson.

> **Caution.** $\lambda = 2\pi/k$ measures the spacing of wavefronts along $\mathbf k$, never along an
> arbitrary axis. A wave crossing a screen at a shallow angle paints stripes far wider than its own
> wavelength — the same projection that lets a grating with $s \gg \lambda$ still diffract, and the
> same effect that makes a "wavelength read off the screen" meaningless unless you also state the
> angle.

### Two plane waves: interference in space

Because the wave equation is linear, the sum of two plane-wave solutions with the same $\omega$ but
different directions $\mathbf k_1, \mathbf k_2$ (equal lengths $\omega/c$, different orientations) is
again a solution. Factor out the mean phase, $\mathbf k_\pm = \tfrac12(\mathbf k_1 \pm \mathbf k_2)$:

$$
\phi = e^{i(\mathbf k_1\cdot\mathbf r - \omega t)} + e^{i(\mathbf k_2\cdot\mathbf r - \omega t)}
= 2\cos\!\big(\mathbf k_-\!\cdot\mathbf r\big)\; e^{i(\mathbf k_+\cdot\mathbf r - \omega t)} .
$$

Read it as an ordinary travelling wave — direction $\mathbf k_+$, the bisector — multiplied by a
**stationary spatial envelope** $2\cos(\mathbf k_-\cdot\mathbf r)$ that does not move at all. The
intensity $\propto|\phi|^2 = 4\cos^2(\mathbf k_-\cdot\mathbf r)$ is a set of straight, motionless
bright bands perpendicular to $\mathbf k_- $, spaced by

$$
\Lambda = \frac{\pi}{|\mathbf k_-|} = \frac{\lambda}{2\sin(\alpha/2)} ,
$$

where $\alpha$ is the angle between $\mathbf k_1$ and $\mathbf k_2$ (using
$|\mathbf k_1 - \mathbf k_2| = 2k\sin(\alpha/2)$ for equal lengths). Nearly parallel beams give
coarse fringes; beams meeting head-on ($\alpha = \pi$) give $\Lambda = \lambda/2$ — the 3D version of
the standing wave of [P.1.1](01-waves-and-the-wave-equation.md), whose nodes sit half a wavelength
apart. This is the operating principle of holography, of laser interference lithography, and of the
**optical lattices** that hold cold atoms in place for quantum simulation.

The demo tilts two unit-amplitude beams by $\pm q$ about the $x$ axis, so
$\mathbf k_- = q\,\hat{\mathbf y}$ and the fringes repeat every $\Lambda = \pi/q$. Check that the
intensity keeps no trace of $x$ or $t$, and read the spacing from crest to crest:

```qm-demo two-beam-fringes

```

### Point sources and the Huygens–Fresnel construction

The other elementary solution is the **spherical wave** radiated by a point source at the origin,

$$
\phi(\mathbf r, t) = \frac{A}{r}\,e^{i(kr - \omega t)}, \qquad r = |\mathbf r| ,
$$

whose wavefronts are concentric spheres (circles, in a 2D cross-section) expanding at $c$. The $1/r$
is energy conservation, not decoration: intensity $\propto |\phi|^2 = A^2/r^2$ spread over a sphere of
area $4\pi r^2$ carries constant total power. Far from the source, a small patch of a huge sphere is
indistinguishable from a plane — which is why a distant star delivers plane waves.

**Huygens' principle** (1678), sharpened by Fresnel: *every point of a wavefront acts as a source of
secondary spherical wavelets, and the field at a later time is their superposition.* It is a
computational recipe, and its power is best seen by watching it converge. Illuminate a slit of width
$d$ with a plane wave from the left and rebuild the transmitted field from $N$ equally spaced point
sources across the opening:

- **$N = 3$.** A lumpy mess. Three circles cannot imitate a wavefront; the result is a three-source interference pattern, not a beam.
- **$N = 5$.** Recognizably wrong near the slit, but already plausible far away — the wavelets' common tangent begins to look like a straight front.
- **$N = 9$.** The right-hand edges of the circles visibly line up along a straight line. Plane wavefronts emerge on the far side, as though the incident wave had simply *marched through* the gap.
- **$N = 17$.** Converged, for the purpose of drawing pictures. Adding more sources changes nothing visible.

The moral is that a plane wave "continuing in a straight line" is not a primitive fact — it is the
*collective* result of infinitely many wavelets whose sideways contributions cancel. And that
immediately tells you what a finite aperture must do: with the wavefront **clipped** at the edges,
the cancellation is incomplete, so the transmitted beam cannot stay perfectly collimated. It spreads.
The rest of the lesson is the size of that spread.

```mermaid
flowchart LR
    A["Plane wave<br/>hits aperture of width d"] --> B["Huygens: every point in the gap<br/>re-radiates a spherical wavelet"]
    B --> C["Wavelets superpose"]
    C --> D["Interior: sideways contributions<br/>cancel → beam goes straight"]
    C --> E["Edges: cancellation incomplete<br/>(no neighbours beyond the rim)"]
    E --> F["Beam fans out by θ ~ λ/d<br/>= diffraction"]
    D --> F
```

### The diffraction angle $\theta \sim \lambda/d$

A wave leaving a source or aperture of transverse width $d$ emerges as a beam that spreads into a
cone of half-angle

$$
\boxed{\;\theta \sim \frac{\lambda}{d}\;}
$$

— the single most useful estimate in wave physics. Three complementary derivations, all worth having:

**1. Cancellation (the textbook argument).** Pair each Huygens source in the top half of the slit with
its partner $d/2$ below. In the direction $\theta$, that pair has a path difference
$(d/2)\sin\theta$. Every pair cancels when this equals $\lambda/2$, i.e. at
$\sin\theta_1 = \lambda/d$ — the **first zero** of the single-slit pattern. Between $-\theta_1$ and
$+\theta_1$ sits the central lobe containing most of the energy, so its half-width $\lambda/d$ *is*
the diffraction angle. (The full pattern is $I(\theta) \propto [\sin\beta/\beta]^2$ with
$\beta = \pi d\sin\theta/\lambda$, the classic $\mathrm{sinc}^2$ envelope of
[P.3.2](../c03-wave-particle-duality/02-matter-as-waves.md).)

**2. Transverse wavevector.** Confining the wave to width $d$ means the field is nonzero only over an
interval $\Delta x \approx d$. Fourier analysis
([0.3.2](../../term-0-foundations/c03-fourier-methods/02-fourier-series-transforms.md)) then requires
a spread of transverse wavenumbers $\Delta k_x \gtrsim 2\pi/d$. Since a component $k_x$ corresponds to
propagation at angle $\sin\theta = k_x/k$, the angular spread is
$\Delta\theta \approx \Delta k_x/k = \lambda/d$. Same answer, and this one shows *why*: **diffraction
is the uncertainty principle of the Fourier transform**, no quantum mechanics required. When $\hbar$
arrives, multiply both sides by it and this becomes $\Delta x\,\Delta p_x \gtrsim \hbar$
([P.4.3](../c04-schrodinger-equation/03-matter-waves-uncertainty-momentum.md)) — the *same theorem*,
re-labelled.

**3. Dimensional analysis.** The only length scales are $\lambda$ and $d$; an angle must be their
ratio. This is why the estimate deserves the "$\sim$": prefactors depend on aperture shape (a circular
aperture gives $\theta = 1.22\lambda/D$, the Rayleigh criterion), but the scaling never changes.

The relation is **inverse**, and the numbers are worth feeling:

| Aperture | Behaviour |
| --- | --- |
| $d = 4\lambda$ | $\theta \approx 0.25$ rad $\approx 14^\circ$ — a recognizable, mildly spreading beam |
| $d = 2\lambda$ | $\theta \approx 0.5$ rad $\approx 30^\circ$ — a broad fan |
| $d = \lambda$ | $\theta \approx 1$ rad $\approx 57^\circ$ — nearly hemispherical; the slit is now essentially a point source |

**Larger aperture, smaller angle; smaller aperture, larger angle.** Squeeze a beam and it fights back.
This single inequality sets the resolution limit of every microscope and telescope, the minimum spot
size of a lithography stepper, and the divergence of every laser and antenna beam ever built.

### Diffraction from periodic structures

Now replace one aperture with a row of $N$ identical scatterers spaced by $s$, illuminated by a
monochromatic plane wave. Each scatterer radiates a spherical wavelet; their sets of concentric
circles interfere. In a general direction the $N$ contributions carry unrelated phases and cancel; the
survivors are the directions where **every scatterer arrives in step**.

Take a direction at angle $\theta$ to the incident beam (which arrives along the normal). The path
difference between wavelets from *adjacent* scatterers is $s\sin\theta$ — read straight off the
right triangle whose hypotenuse is $s$. Constructive interference for all $N$ at once requires that
this be a whole number of wavelengths:

$$
\boxed{\;s\sin\theta_m = m\lambda \quad\Longleftrightarrow\quad \sin\theta_m = \frac{m\lambda}{s},
\qquad m = 0, \pm1, \pm2, \dots\;}
$$

the **grating equation**. The integer $m$ labels the **diffraction order**:

- **$m = 0$** — straight ahead, $\theta_0 = 0$. Zero path difference for any spacing or wavelength: the **zeroth order** always exists and is not dispersive.
- **$m = \pm1$** — the **first orders**, one deflected up and one down, at $\sin\theta_{\pm1} = \pm\lambda/s$. (With normal incidence the geometry is symmetric, so the sign is bookkeeping, not physics.)
- **$m = \pm2, \pm3,\dots$** — successively higher orders, each needing an extra wavelength of path per scatterer pair.

Since $|\sin\theta_m| \le 1$, order $m$ exists **only if** $|m| \le s/\lambda$: the number of observable
orders is set by the spacing measured in wavelengths.

$$
m_{\max} = \left\lfloor \frac{s}{\lambda} \right\rfloor .
$$

Two consequences run in opposite directions, and confusing them is the classic error:

- **More scatterers ⇒ sharper beams.** With $N$ sources the intensity is
  $I \propto [\sin(N\delta/2)/\sin(\delta/2)]^2$, $\delta = 2\pi s\sin\theta/\lambda$: the maxima keep
  their *positions* but their width shrinks as $1/N$. Two slits give broad $\cos^2$ fringes
  ([P.3.2](../c03-wave-particle-duality/02-matter-as-waves.md)); a few thousand give the needle-sharp
  spots that make a grating a precision spectrometer.
- **Wider spacing ⇒ more, but closer-packed, beams.** Increasing $s$ *decreases* every
  $\sin\theta_m = m\lambda/s$, crowding the orders toward the axis while admitting more of them. At
  $s = 1.5\lambda$ only $m = 0, \pm1$ survive, widely splayed; by $s = 4\lambda$ there are nine orders
  packed into the same angular range.

The wavelength dependence is what makes gratings *instruments*: $\theta_m$ depends on $\lambda$, so
white light is fanned into a spectrum, and measuring $\theta_m$ **measures $\lambda$**. Point the same
geometry the other way — known $\lambda$, unknown spacing — and it measures $s$. That inversion is
X-ray crystallography, and it is exactly the experiment Davisson and Germer performed with electrons
in 1927, using a nickel crystal's atomic rows as the grating: their scattered peak at $50^\circ$ from
$d = 0.215\ \mathrm{nm}$ rows *measured* an electron wavelength of $0.165\ \mathrm{nm}$, against de
Broglie's predicted $0.167\ \mathrm{nm}$ ([P.3.2](../c03-wave-particle-duality/02-matter-as-waves.md)).
A classical instrument, built entirely from the mathematics of this section, is what proved matter is
wavelike.

---

## Worked Examples

### Example 1 — Two crossed laser beams write an optical lattice

Two beams of a He–Ne laser, $\lambda = 632.8\ \mathrm{nm}$, cross at $\alpha = 30^\circ$. What is the
fringe spacing, and what does it become for counter-propagating beams?

Using $\Lambda = \lambda/[2\sin(\alpha/2)]$ with $\alpha/2 = 15^\circ$, $\sin 15^\circ = 0.2588$:

$$
\Lambda = \frac{632.8\ \mathrm{nm}}{2(0.2588)} = 1.22\ \mathrm{\mu m} .
$$

Counter-propagating ($\alpha = 180^\circ$): $\Lambda = \lambda/2 = 316\ \mathrm{nm}$, the tightest
spacing two beams of this colour can produce — and the standard geometry for trapping cold atoms one
per well. Note the fringes are *stationary* even though both beams travel at $c$: the envelope
$\cos(\mathbf k_-\cdot\mathbf r)$ carries no time dependence.

### Example 2 — Reading a grating, then reading a crystal

**(a)** A grating with 600 lines/mm ($s = 1/600\ \mathrm{mm} = 1.667\ \mathrm{\mu m}$) is illuminated
at normal incidence by $\lambda = 550\ \mathrm{nm}$. Which orders exist, and where?

$\lambda/s = 550/1667 = 0.330$. So $m_{\max} = \lfloor 1/0.330\rfloor = 3$, and

$$
\theta_1 = \arcsin(0.330) = 19.3^\circ,\quad
\theta_2 = \arcsin(0.660) = 41.3^\circ,\quad
\theta_3 = \arcsin(0.990) = 81.9^\circ ,
$$

plus their negatives and $\theta_0 = 0$: **seven beams**, with the third order grazing the plane of the
grating. Red light at $700\ \mathrm{nm}$ has $\lambda/s = 0.420$, so only orders $0, \pm1, \pm2$
survive and each sits at a larger angle than green's — the fan of a spectrum.

**(b)** Same equation, unknown spacing. First-order diffraction of $\lambda = 0.154\ \mathrm{nm}$
X-rays (Cu K$\alpha$) is observed at $\theta_1 = 21.0^\circ$. Then

$$
s = \frac{\lambda}{\sin\theta_1} = \frac{0.154}{0.3584} = 0.430\ \mathrm{nm} ,
$$

an atomic-scale spacing measured with nothing but an angle and a wavelength. Note the requirement
$s > \lambda$ for *any* first order to exist: this is why you cannot see atoms with visible light —
$550\ \mathrm{nm}$ against a $0.43\ \mathrm{nm}$ lattice gives $\lambda/s = 1279 \gg 1$, no orders
beyond $m = 0$, no information. Probing a structure requires a wavelength no larger than the
structure.

---

## Hands-on (Python)

```python
import numpy as np
import matplotlib.pyplot as plt

# --- 1. Two plane waves crossing: stationary fringes in space ---------------
lam   = 1.0                                     # wavelength (arbitrary units)
k     = 2*np.pi/lam
alpha = np.deg2rad(30.0)                        # full angle between the beams

# Both wavevectors have length k; they straddle the z-axis by +/- alpha/2.
k1 = k*np.array([ np.sin(alpha/2), np.cos(alpha/2)])
k2 = k*np.array([-np.sin(alpha/2), np.cos(alpha/2)])

x = np.linspace(-6, 6, 600); z = np.linspace(0, 8, 400)
X, Z = np.meshgrid(x, z)
phi = np.exp(1j*(k1[0]*X + k1[1]*Z)) + np.exp(1j*(k2[0]*X + k2[1]*Z))   # t = 0

plt.imshow(np.abs(phi)**2, extent=[x[0], x[-1], z[0], z[-1]],
           origin="lower", aspect="auto", cmap="viridis")
plt.xlabel("x"); plt.ylabel("z"); plt.title("Two crossed plane waves")
plt.colorbar(label=r"$|\phi|^2$"); plt.show()

print("predicted fringe spacing:", lam/(2*np.sin(alpha/2)))   # 1.932
# Expected: vertical bright bands, uniformly spaced by ~1.93 lambda, running
# along z. They do not move with t -- only the carrier does.
```

```python
# --- 2. Huygens convergence: N point sources filling one aperture ----------
lam, kk = 1.0, 2*np.pi                          # lambda = 1
d = 6.0*lam                                     # aperture width
x = np.linspace(-12, 12, 500); z = np.linspace(0.15, 16, 400)
X, Z = np.meshgrid(x, z)

fig, axes = plt.subplots(1, 4, figsize=(14, 3.6), sharey=True)
for ax, N in zip(axes, (3, 5, 9, 17)):
    ys = np.linspace(-d/2, d/2, N)              # source positions in the gap
    field = np.zeros_like(X, dtype=complex)
    for y0 in ys:                               # each source: circular wavelet
        r = np.hypot(X - y0, Z)
        field += np.exp(1j*kk*r)/np.sqrt(r)     # 2D wavelet falls as 1/sqrt(r)
    ax.imshow(field.real, extent=[x[0], x[-1], z[0], z[-1]],
              origin="lower", aspect="auto", cmap="RdBu")
    ax.set_title(f"N = {N}"); ax.set_xlabel("x")
axes[0].set_ylabel("z (propagation)")
plt.tight_layout(); plt.show()
# Expected: N=3 lumpy interference; N=9 straight wavefronts appear beyond the
# gap; N=17 converged. In every panel the beam fans out past |x| ~ z*lam/d.
```

```python
# --- 3. Single slit and N-slit grating: envelope, orders, sharpening -------
def slit_pattern(sin_t, d_over_lam):
    """sinc^2 envelope of one slit of width d."""
    beta = np.pi*d_over_lam*sin_t
    return np.sinc(beta/np.pi)**2               # np.sinc(u) = sin(pi u)/(pi u)

def grating_pattern(sin_t, s_over_lam, N):
    """N equally spaced scatterers: [sin(N delta/2)/(N sin(delta/2))]^2."""
    delta = 2*np.pi*s_over_lam*sin_t
    num, den = np.sin(N*delta/2), np.sin(delta/2)
    out = np.divide(num, den, out=np.full_like(num, N), where=np.abs(den) > 1e-12)
    return (out/N)**2

sin_t = np.linspace(-1, 1, 4000)

# (a) diffraction angle scales as lambda/d
plt.figure(figsize=(7, 4))
for d_lam in (1.0, 2.0, 4.0):
    plt.plot(np.degrees(np.arcsin(sin_t)), slit_pattern(sin_t, d_lam),
             label=f"d = {d_lam:.0f}$\\lambda$  (first zero at "
                   f"{np.degrees(np.arcsin(min(1/d_lam, 1))):.0f}°)")
plt.xlabel("θ (degrees)"); plt.ylabel("I / I(0)"); plt.legend(); plt.show()
# Expected: first zeros at 90°, 30°, 14.5° -- halving lambda/d halves the angle.

# (b) grating orders and the 1/N sharpening
s_lam = 2.5
plt.figure(figsize=(7, 4))
for N in (2, 5, 20):
    plt.plot(np.degrees(np.arcsin(sin_t)), grating_pattern(sin_t, s_lam, N),
             lw=1.0, label=f"N = {N}")
for m in range(-int(s_lam), int(s_lam) + 1):    # predicted order positions
    plt.axvline(np.degrees(np.arcsin(m/s_lam)), color="gray", ls=":", lw=0.7)
plt.xlabel("θ (degrees)"); plt.ylabel("I / I(0)")
plt.title(f"s = {s_lam}$\\lambda$: orders m = 0, ±1, ±2"); plt.legend(); plt.show()
# Expected: peaks land exactly on the dotted lines predicted by sin(theta)=m*lam/s
# (0°, ±23.6°, ±53.1°); N=2 gives broad cos^2 humps, N=20 gives sharp spikes at
# the SAME angles -- N sets the width, s sets the positions.

for s_lam in (1.5, 2.0, 2.5, 3.0, 4.0):
    print(f"s = {s_lam}λ -> {2*int(s_lam) + 1} orders, "
          f"first at {np.degrees(np.arcsin(1/s_lam)):5.1f}°")
# s = 1.5λ -> 3 orders, first at  41.8°
# s = 2.0λ -> 5 orders, first at  30.0°
# s = 2.5λ -> 5 orders, first at  23.6°
# s = 3.0λ -> 7 orders, first at  19.5°
# s = 4.0λ -> 9 orders, first at  14.5°   <- wider spacing: more, tighter beams
```

---

## Exercises

**E1 (easy).** A plane wave of wavelength $\lambda = 500\ \mathrm{nm}$ travels in the $xz$-plane at
$30^\circ$ from the $z$-axis. Write $\mathbf k$, and find the spacing of the stripes it prints on the
plane $z = 0$.

<details><summary>Solution</summary>

$k = 2\pi/\lambda = 1.257\times10^7\ \mathrm{m^{-1}}$, so
$\mathbf k = k(\sin 30^\circ\,\hat{\mathbf x} + \cos 30^\circ\,\hat{\mathbf z}) = (6.28\times10^6\,\hat{\mathbf x} + 1.088\times10^7\,\hat{\mathbf z})\ \mathrm{m^{-1}}$.
On $z = 0$ the phase varies as $k_xx$, so the period is
$2\pi/k_x = \lambda/\sin 30^\circ = 1000\ \mathrm{nm}$ — twice the wavelength. Stripes on a screen are
always *wider* than $\lambda$, by the factor $1/\sin\theta$.
</details>

**E2 (easy).** Show by direct substitution that $\phi = A\cos(\mathbf k\cdot\mathbf r - \omega t)$
solves the 3D wave equation under the same condition $k = \omega/c$, and explain why the complex form
was worth using anyway.

<details><summary>Solution</summary>

$\nabla\phi = -A\mathbf k\sin(\mathbf k\cdot\mathbf r - \omega t)$ and
$\nabla^2\phi = -A\,\mathbf k\cdot\mathbf k\,\cos(\cdot) = -k^2\phi$; also
$\partial_t^2\phi = -\omega^2\phi$. Substituting gives $(-k^2 + \omega^2/c^2)\phi = 0$, hence
$k = \omega/c$ ✓ — unsurprising, since $\cos$ is the real part of the exponential and the equation has
real coefficients. The exponential is worth it because differentiation becomes *multiplication* by
$i\mathbf k$ (no sign-flipping between sin and cos), and superposing waves becomes adding complex
numbers. In quantum mechanics the complex form stops being a convenience and becomes the state itself
([P.4.1](../c04-schrodinger-equation/01-schrodinger-equation-born-rule.md)).
</details>

**E3 (medium).** A laser of wavelength $\lambda = 1.0\ \mathrm{\mu m}$ leaves an aperture of diameter
$D = 1.0\ \mathrm{mm}$. Estimate the beam diameter after $1\ \mathrm{km}$, and after
$3.8\times10^5\ \mathrm{km}$ (the Moon). Then explain why a bigger telescope sees finer detail.

<details><summary>Solution</summary>

$\theta \sim \lambda/D = 10^{-6}/10^{-3} = 10^{-3}$ rad. After $L = 1\ \mathrm{km}$ the beam has grown
by roughly $2\theta L = 2\ \mathrm{m}$; after $3.8\times10^5\ \mathrm{km}$, by
$2\times10^{-3}\times3.8\times10^{8}\ \mathrm{m} \approx 760\ \mathrm{km}$ — which is why lunar
laser-ranging returns a vanishing fraction of the light it sends, and why the Apollo experiments used
the largest available launch telescope. Same relation, run backwards, for imaging: a telescope of
aperture $D$ cannot resolve angles below $\approx 1.22\lambda/D$, because each point source arrives as
a blob of that width. Doubling $D$ halves the blob. Resolution *is* diffraction.
</details>

**E4 (medium).** Show that for a grating with $s < \lambda$ only the zeroth order exists, and give the
physical reading. Then find how large $s/\lambda$ must be to produce at least 5 beams.

<details><summary>Solution</summary>

Order $m$ requires $\sin\theta_m = m\lambda/s$ with $|\sin\theta_m| \le 1$, i.e. $|m| \le s/\lambda$.
If $s < \lambda$ then $s/\lambda < 1$, so no nonzero integer qualifies: only $m = 0$, the undeflected
beam. Physically, adjacent scatterers can never accumulate a full wavelength of path difference no
matter how far you swing the detector — the structure is too fine for this wavelength to resolve, and
the wave passes as if through a uniform medium (the basis of metamaterials and of anti-reflection
sub-wavelength textures). For 5 beams we need $m = 0, \pm1, \pm2$, hence $s/\lambda \ge 2$: with
$s = 2\lambda$ exactly, $\theta_{\pm2} = \pm90^\circ$ (grazing), so $s/\lambda > 2$ for five beams that
are actually observable.
</details>

**E5 (hard).** Derive the $N$-slit intensity $I \propto [\sin(N\delta/2)/\sin(\delta/2)]^2$ with
$\delta = 2\pi s\sin\theta/\lambda$, then show its principal maxima occur exactly at the grating angles
and that their angular width scales as $1/N$.

<details><summary>Solution</summary>

Scatterer $n$ (at height $ns$) contributes an extra path $ns\sin\theta$, hence phase $n\delta$. The
total amplitude is a geometric series:

$$
A = \sum_{n=0}^{N-1}e^{in\delta} = \frac{1 - e^{iN\delta}}{1 - e^{i\delta}}
= e^{i(N-1)\delta/2}\,\frac{\sin(N\delta/2)}{\sin(\delta/2)} ,
$$

using $1 - e^{i\vartheta} = -2i\,e^{i\vartheta/2}\sin(\vartheta/2)$ twice; the modulus squared gives the
stated $I$. **Principal maxima:** when $\delta = 2\pi m$ both sine factors vanish, and l'Hôpital (or
noting each term is $e^{i2\pi mn} = 1$) gives $|A| = N$, so $I \propto N^2$. The condition
$\delta = 2\pi m$ is $2\pi s\sin\theta/\lambda = 2\pi m$, i.e. $\sin\theta_m = m\lambda/s$ ✓ —
independent of $N$. **Width:** the nearest zero has $N\delta/2 = \pi m N + \pi$, i.e.
$\Delta\delta = 2\pi/N$ from the peak, so $\Delta(\sin\theta) = \lambda/(Ns)$: the peak narrows as
$1/N$ while its height grows as $N^2$ — total energy $\propto N$, as conservation demands. Positions
from $s$, sharpness from $N$: that is why spectrometers use gratings ruled with $10^4$–$10^5$ lines.
</details>

---

## Checkpoint

1. Write the 3D wave equation and show that $\exp[i(\mathbf k\cdot\mathbf r - \omega t)]$ solves it. What condition on $\mathbf k$ is required, and what is *not* constrained?
2. Two plane waves of the same frequency cross at angle $\alpha$. Describe the resulting pattern and give its spacing. Does it move?
3. State Huygens' principle. Why does it predict that a wave leaving a finite aperture cannot stay perfectly collimated?
4. Estimate the diffraction angle of an aperture of width $d$, and state which way the relation runs. What is the Fourier-analysis reading of the same estimate?
5. Write the grating equation, define the diffraction order, and say how many orders exist for $s = 3.4\lambda$.

<details><summary>Answers</summary>

1. $\nabla^2\phi - c^{-2}\partial_t^2\phi = 0$. Two applications of $\nabla \to i\mathbf k$ give
   $\nabla^2\phi = -k^2\phi$, and $\partial_t^2\phi = -\omega^2\phi$, so the equation reduces to
   $-k^2 + \omega^2/c^2 = 0$, i.e. $k = \omega/c$. Only the *length* of $\mathbf k$ is fixed; the
   direction is completely free, so every wavevector on the sphere of radius $\omega/c$ is a solution.
2. Straight, stationary intensity fringes perpendicular to $\mathbf k_1 - \mathbf k_2$, spaced
   $\Lambda = \lambda/[2\sin(\alpha/2)]$. The pattern does **not** move: the travelling factor is the
   carrier $e^{i(\mathbf k_+\cdot\mathbf r - \omega t)}$, while the envelope
   $\cos(\mathbf k_-\cdot\mathbf r)$ has no time dependence.
3. Every point of a wavefront is a source of secondary spherical wavelets; the field later is their
   superposition. Straight-line propagation is the *collective* cancellation of the wavelets' sideways
   contributions, so clipping the wavefront at an aperture's edges removes the neighbours that would
   have done the cancelling — the beam necessarily spreads.
4. $\theta \sim \lambda/d$: **larger aperture, smaller angle; smaller aperture, larger angle.** In
   Fourier terms, confining the field to $\Delta x \approx d$ forces a transverse-wavenumber spread
   $\Delta k_x \gtrsim 2\pi/d$, and $\Delta\theta \approx \Delta k_x/k = \lambda/d$ — diffraction is
   the Fourier uncertainty relation, the classical ancestor of $\Delta x\,\Delta p \gtrsim \hbar$.
5. $\sin\theta_m = m\lambda/s$; $m$ is the diffraction order, the number of whole wavelengths of path
   difference between adjacent scatterers. For $s = 3.4\lambda$, $|m| \le 3$, so
   $m = 0, \pm1, \pm2, \pm3$ — **seven** beams.

</details>

---

## Further Reading

- **[Hec]** Hecht, *Optics*, Ch. 9–10 — interference, Huygens–Fresnel, single-slit and grating diffraction; the definitive classical treatment of everything in this lesson.
- **[ER]** Eisberg & Resnick, §3-1 — the same diffraction mathematics turned into the detector that revealed matter waves.
- **[Gri]** Griffiths & Schroeter, §1.6 — how the Fourier reading of $\theta \sim \lambda/d$ becomes the uncertainty principle.

---

← Prev: [Waves & the Wave Equation](01-waves-and-the-wave-equation.md) · Up: [Pre-Term](../README.md) · Next: [Lagrangian Mechanics](03-lagrangian-mechanics.md) →
