how to find a spline function from given control points

1.6k Views Asked by At

consider having an n-amount of control points in 2D space, what's the best way to find the function passing through the start and end points while approximating the path according to the other given control points? i would really appreciate it, if someone can give an example. thanks in advance

2

There are 2 best solutions below

0
On

The simplest approach is Lagrange interpolation, which is described here. Suppose your points are $\mathbf{P}_i = (x_i, y_i)$ for $i=0,1,\ldots,n$. You assign a parameter value $t_i$ to each point. Then you use Lagrange interpolation (twice) to interpolate the $(x_i,t_i)$ values and the $(y_i,t_i)$ values. A numerical example is given on the page I cited. This process will give you a parametric polynomial curve that passes through all the given points.

In the example you gave in your comment, the points have monotonically increasing $x$ values. Therefore, you can just construct a solution of the form $y = f(x)$, which is simpler than the approach I explained in the first paragraph above. The wikipedia page I cited tells you exactly how to do this using Lagrange polynomials, including a nice numerical example. I can't explain it any better than they did. This will give you a polynomial curve that passes through all the given points. A polynomial curve is a Bezier curve, so you have what you asked for.

If you don't want the curve to pass through the interior points (but only through the first and last ones), then you can use the given points as the coefficients of either a Bezier curve or a b-spline curve. This page explains how.

0
On

It seems to me that what you need is a constrained least square spline fitting with linear equality constraints. Forcing the start and end points becomes the first and last control poles of the spline are the linear equality constraints. You can use either a Bezier curve or a B-spline curve in the least square fitting, but using cubic B-spline curve is always a preferred approach.