I am doing some experiments with optics and ray tracing. This involves calculating the amplitude at various points across the image plane, given a known frequency and an unknown phase and amplitude. Currently I just generate a dozen points on the curve and pick the one with the highest amplitude, but not only is that lazy and inaccurate, it is also very expensive to generate a dozen samples per pixel of the image plane (it involves iterating over hundreds of thousands of samples of the source wavefront).
it would be better to generate two or three samples and then use some kind of curve fitting to get the amplitude. There is probably an algebraic method, but that would involve maths.
So here is my first stab at a curve fitting algorithm. It involves 200 iterations to get a curve match with an error of ~0.01%,
although the method occasionally glitches out with an error of 1%.
Edit: Latest: http://pastebin.java-gaming.org/23f4932542610
When I run it I get output like this:
Error by curve fitting : 0.00263
Error by rough curve sampling : 1.17135
Error by fine curve sampling : 0.28717