1
$\begingroup$

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

  • 2
    Ask on stackoverflow instead.2011-06-06

2 Answers 2

1

People usually use Spline Interpolation.

  • 0
    can this be done with any number of points?2011-06-06
  • 1
    @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.2011-06-06
  • 1
    @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.2011-06-06
  • 0
    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? thanks2011-06-07
  • 0
    @Mike: This method is so standard that I'm sure you can google an implementation by yourself.2011-06-07
1

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: enter image description here