My favorite playthings are drawing on screen and optimizations. So I was the one who did the graph drawing research for the iPhone project.There are several graphing components on the internet available, but all are more generalized than we need.
We don't have GraphKit available on the iPhone, so I think it is the best to work with our own component. It took two days to write the code for it, it's easily used, and it has all the features we need.
As far as I know, there is no curve drawing trough arbitrary points on the iPhone, so one must write his own algorithm for this.
Calculating all points for the curve isn't a good idea, because it consumes lots of processor power, so I've chosen to create segments of lines - more segments, the curve is smoother.
Ok, segments, but how to get new point on the curve to draw these segments?
And here comes the math part - Lagrange Polynomial (you will love this):where N is the number of points we already have.
It's not the best interpolation (best would be natural cubic spline) - we have the start and end points fixed, otherwise the curve ends would fly off fast from the screen with this formula
The drawing itself is based on Quartz2D. If you have the right math formula, the rest is easy. Rock on!