Exact directional sine-wave fit through five points

A rotated sine wave has five unknowns: amplitude A, wavelength λ, phase φ, offset C and propagation angle θ. Five points therefore give a determined system with isolated exact solutions. The smoothest solution is the one with the longest wavelength.

u = x·cosθ + y·sinθ    v = −x·sinθ + y·cosθ    v = A·sin(2π·u/λ + φ) + C

Search landscape

Brighter = smaller leftover error once the best (A cosφ, A sinφ, C) has been fitted for that wavelength and angle. Rings mark the exact solutions, the isolated points where that error is exactly zero (the bright streaks are near misses). Click an entry in the solution list to move the white ring. The top of the chart is λ = ∞, a parabola.

How the solver works

For a fixed wavelength and angle the five equations are linear in (A·cosφ, A·sinφ, C), which leaves two constraints that generally fail. Scanning (λ, θ) therefore turns the problem into finding the zeros of a two-dimensional error function. The page evaluates that error on a grid, takes every local minimum as a seed, polishes each seed with Levenberg–Marquardt on all five unknowns, keeps the roots whose error is below 1e-9 (in units of the points' span), and sorts them by wavelength. The longest wavelength is the smoothest solution. The search starts at λ = ∞ and widens to shorter wavelengths only if nothing is found.