Three.js Sound Wave Propagation (2D Wave Equation)
Simulate acoustic waves in Three.js with a 180×180 finite-difference wave equation, showing double-slit diffraction, two-source interference, a parabolic reflector and a moving source's Doppler effect, with an audible listener probe.
Key topics: wave equation simulation, sound wave propagation, doppler effect, double slit interference, finite difference, three.js physics
Game Over
What this code does
- Wave Equation: u_tt = c²∇²u solved with leapfrog finite differences, stable while the Courant number c²Δt²/Δx² stays below 0.5.
- Boundaries: walls clamp u = 0 and reflect; a quadratic sponge layer at the edges absorbs outgoing waves.
- Diffraction & Interference: slits act as new sources (Huygens), making bright and dark fringes at constructive and destructive angles.
- Doppler: wavefronts bunch ahead of a moving source; the listener's tone shifts by f′ = f·c/(c − v).
- Listener: the cone samples the field, and its RMS drives the loudness of the audible tone.
- Controls: scenario, source frequency, wave speed, damping, height scale, absorbing edges and reset.
Related Demos
Continue Learning
JavaScript Implementation
// 2-D wave equation, leapfrog: next = 2u − prev + c²·∇²u (Courant number c² < 0.5)
for (let y = 1; y < N - 1; y++) for (let x = 1; x < N - 1; x++) {
const i = y * N + x
if (wall[i]) { next[i] = 0; continue } // reflecting obstacle
const lap = u[i - 1] + u[i + 1] + u[i - N] + u[i + N] - 4 * u[i]
next[i] = 2 * u[i] - prev[i] + 0.24 * lap
}
next[source] = Math.sin(t * omega); [prev, u, next] = [u, next, prev]
u.forEach((v, i) => positions.setY(i, v * 0.5)) // displaced PlaneGeometry