Nonlinear wave equations and constrained harmonic motion