# creating the smoothest curve

I have this iPhone app that has an array containing around 50 to 100 points. How do I calculate the smoothest curve that will fit the points? It can be bezier, cubic, quadratic, whatever. It just have to look smooth and fit as much as possible all points (obviously, as I did in my drawing, to create a smooth curve, some points have to be created out of the original set... no problem).

Can you guys please point me to a code is Objective-C, C or C++?

See an image here, to know what I mean: http://i.stack.imgur.com/UoRQB.png

thanks

-
Ask on stackoverflow instead. –  Yuval Filmus Jun 6 '11 at 16:10

People usually use Spline Interpolation.

-
can this be done with any number of points? –  Mike Jun 6 '11 at 16:50
@Mike: it looks that way, based on the Wikipedia discussion. On the otherhand, a spline interpolation will always pass through all the points, which may not be exactly what you want, according to your picture. –  mac Jun 6 '11 at 17:09
@Mike: Yes. And it will look smooth. It will however be an actual interpolation, i.e. the resulting curve will pass through all your points. –  Gunnar Þór Magnússon Jun 6 '11 at 20:46
my math is too rusty for that. Can you point me to a code in C, C++ or Objective-C that can show me the way? thanks –  Mike Jun 7 '11 at 2:44
@Mike: This method is so standard that I'm sure you can google an implementation by yourself. –  Yuval Filmus Jun 7 '11 at 14:11

What you want is LOWESS, or LOcally WEighted Scatterplot Smoothing. This performs a sequence of weighted linear regressions as you move along the curve, assigning more weight to nearby points and less to far away points. Read about it here.

This is implemented in the open-source statistics package R, as the function lowess. I don't know if someone has implemented it in C, C++ or Objective-C but you could take a look at the R code and work from there.

Here's a quick plot that I made in R:

-
thanks, I will take a look. –  Mike Jun 6 '11 at 18:04