# Which Interpolation should I use to create a curve?

I'm pretty weak in the field of mathematics, but a strong programmer. I am looking for a mathematical solution that, given two points on a line will give me a curve between them, including those two points within the curve itself.

For instance, if I have a set of points { (0, 3) (1,10) } I'd like a mathematical way to generate points between the two (I believe this is called interpolate) to create a curve that will contain { (0,3) (1,10) }

Will Linear Interpolation give me this?

Thank you

-
All sorts of curves can pass through 2 points. The simplest is of course a straight line. Do you have more conditions, constraints or requirements on the interpolated curve? – user2468 Aug 16 '12 at 1:54

You could do that, but if a straight line is acceptable, the best-of-breed algorithm for calculating which pixels to plot is Bresenham's algorithm. It is easy to program, produces good-looking output, and it is extremely efficient.

If you are interested in curved curves, you have a lot of choices. People often use cubic splines, because they are graceful, fit together well, and the algorithm is easy to write and runs quickly. There is a variation of Bresenham's algorithm for circular arcs instead of straight lines. If this isn't enough information, you should consider posting another question that elaborates on what you are looking for.

-
Splines fits the bill - and there are enough variations to fit all of the different requirements. Thank you! – TheNerd Aug 16 '12 at 2:15
You're very welcome. Splines are a really interesting topic, and you'll be glad you looked into them. – MJD Aug 16 '12 at 2:20
It should be noted that there are a lot of variants of cubic splines. In general, if the curve you want to interpolate is closed (e.g. a circle), use a periodic spline; for most other applications, the "not-a-knot" variant works well. The "natural" spline is sometimes used, but almost always the results from the "not-a-knot" look "better". – J. M. Aug 16 '12 at 2:41

You probably want to check out Bézier Curves. You can find a live demo here, just be sure to pick 4 points and then click draw bezier. I know Bézier curves are heavily used in computer graphics, mostly due to the fact you can compute them quickly. You need 4 points to define them, but if you keep two of the points fixed, the other two points can be anything, changing them just changes the shape of the curve. By the way the javascript source for jsDraw2d can be found here. If that's not enough, this should keep you busy ;)

-

You also might want to check out Lagrange interpolation. The idea is that you can create a polynomial that goes through the given points, provided that the points arn't lined up vertically. Here's the link to the wikipedia article.

http://en.wikipedia.org/wiki/Lagrange_polynomial

-
A bit on the wiggly side, though, if there are a lot of points... – J. M. Aug 16 '12 at 3:11