Forcing Bezier Interpolation

2.7k Views Asked by At

I found this very informative site that discusses forcing bezier interpolation and the site gives formulae for calculating the control points so that the curve goes through a set of four points, y0, y1, y2 and y3, for t=0, 1/3, 2/3, 1 respectively.

The formulae given on this site are as follows:

P0 = y0
P1 = ( -5 * y0 + 18 * y1 -  9 * y2 + 2 y3 ) / 6
P2 = (  2 * y0 -  9 * y1 + 18 * y2 - 5 y3 ) / 6
P3 = y3

What I am looking for is a more general form of the formulae for calculating P1 and P2. So instead of having fixed values of t of 1/3 and 2/3, rather to express them as a function of t1 and t2, where t1 is the value of t for point y1 and t2 is the value of t for y3. Can someone please help in deriving these more general formulae?

2

There are 2 best solutions below

1
On

Without going into the full theoretical background, Bézier curves use a set of polynomials called Bernstein polynomials to weight the points. For a cubic Bézier, which seems to be what your question is about, this results in the parametric definition $$P(t) = (1-t)^3 P_0 + 3t(1-t)^2 P_1 + 3t^2(1-t) P_2 + t^3 P_3$$

When $t = 0$ this gives simply $P(0) = P_0$, and similarly $P(1) = P_3$. So we only have two degrees of freedom in forcing the curve to pass through your intermediate control points. As the site you linked mentioned, we can set up simultaneous equations:

$$\begin{eqnarray*} & P_0 & & & & & = & y_0 \\ (1-t_1)^3 & P_0 & + 3t_1(1-t_1)^2 & P_1 + 3t_1^2(1-t_1) & P_2 + t_1^3 & P_3 & = & y_1 \\ (1-t_2)^3 & P_0 & + 3t_2(1-t_2)^2 & P_1 + 3t_2^2(1-t_2) & P_2 + t_2^3 & P_3 & = & y_2 \\ & & & & & P_3 & = & y_3 \end{eqnarray*}$$

which easily reduce to

$$\begin{eqnarray*}3t_1(1-t_1)^2 & P_1 + 3t_1^2(1-t_1) & P_2 & = & y_1 - (1-t_1)^3 y_0 - t_1^3 y_3 \\ 3t_2(1-t_2)^2 & P_1 + 3t_2^2(1-t_2) & P_2 & = & y_2 - (1-t_2)^3 y_0 - t_2^3 y_3 \end{eqnarray*}$$

I assume you can take it from here.

2
On

A couple of comments (but too long for the comment box, I think).

First, if you try somewhat harder, you can actually get a planar cubic Bezier curve to interpolate six points, not just four. As you have realized, when interpolating four points, you have to make up parameter values for two of them. The standard choices are $\tfrac13$ and $\tfrac23$, but there's nothing magic about these -- you can use any values you like, and you'll still be able to solve the simultaneous equations and get a curve. But the shape of this curve is highly dependent on the choice you make, so it would be better if you didn't have to make it. By providing another two points, you can remove this troublesome choice. The details are described in this paper. It's probably more complicated than you need, right now, but maybe useful some day.

Secondly ... Peter Taylor's solution involves solving a system of linear equations (or, equivalently, inverting a 4x4 matrix). This isn't very difficult, but you can avoid it by using Lagrange polynomials. Once you have chosen parameter values for the two interior points, you can simply write down the equations of a cubic polynomial curve that passes through the 4 points. This is a standard technique that's explained in any decent numerical analysis text. There are some simple numerical examples on this Wikipedia page. Once you've done this, you might want to convert the curve from polynomial ("power basis") form to Bezier form. This is straightforward and very fast -- it just requires a matrix multiplication.

Peter's solution is simple and easy to implement, and it probably suits your needs. If you want to try either of the alternatives I suggested, ask again, and I can give you more details.