Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

share|improve this question
1  
Ask on stackoverflow instead. –  Yuval Filmus Jun 6 '11 at 16:10

2 Answers 2

up vote 1 down vote accepted

People usually use Spline Interpolation.

share|improve this answer
    
can this be done with any number of points? –  Mike Jun 6 '11 at 16:50
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. –  mac Jun 6 '11 at 17:09
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. –  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: enter image description here

share|improve this answer
    
thanks, I will take a look. –  Mike Jun 6 '11 at 18:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.