Bezier splines:
A very popular interpolating spline is the Bezier spline. Unlike the Hermite spline, Bezier splines allow the user to do all manipulation by dragging around points. Here we have our two end points P_{1} and P_{4}, which the curve goes through (which is why it's called an interpolating spline) but also two other "in-between" points P_{2} and P_{3}, that guide the direction of the curve.
As we said in class, the Bezier spline is made from successively nesting linear interpolations.
The coefficients that you get when you do successive nested linear transformations are called the Bernstein polynomials, named for the mathematician who discovered them. Bezier cubic spline functions are simply the third order Bernstein polynomials.
Let's go over the math: We can implement linear interpolation by:
lerp(t, P_{1}, P_{2}) = (1-t) P_{1} + t P_{2}We can define a parabolic (ie: 2nd order) parametric curve, given three points P_{1}, P_{2}, P_{3}, by nested linear interpolations:
lerp(t, lerp(t, P_{1}, P_{2}), lerp(t, P_{2}, P_{3})) =Multiplying this out gives: (1-t)^{2} P_{1} + 2(1-t) t P_{2} + t^{2} P_{3}(1-t) ((1-t) P_{1} + t P_{2}) + t ((1-t) P_{2} + t P_{3})
Similarly, we can define a cubic (ie: 3rd order) parametric curve given four points P_{1}, P_{2}, P_{3}, P_{4}, by nested linear interpolations:
lerp(t, lerp(t, lerp(t, P_{1}, P_{2}), lerp(t, P_{2}, P_{3})), lerp(t, lerp(t, P_{2}, P_{3}), lerp(t, P_{3}, P_{4}))) =(1-t)^{3} P_{1} + 3(1-t)^{2} t P_{2} + 3(1-t) t^{2} P_{3} + t^{3} P_{4}
Conveniently, the above equation contains four polynomials, each of which multiplies by only one of P_{1}, P_{2}, P_{3} or P_{4}. These are in fact the third-order Bernstein polynomials. I've colored each polynomial differently so you can track them more easily in the following discussion.
These third-order Bernstein polynomials describe the cubic curves modulated by the geometric coefficients P_{1},P_{2},P_{3},P_{4}, respectively, in terms of t^{3},t^{2},t and 1.
Now we just need to convert from one function basis to another:
We want cubic functions | We have geometric functions | |
---|---|---|
The coefficients of the functions on the right give us the columns of the Bezier matrix:
a | -1 | 3 | -3 | 1 | P_{1} | ||
b | ← | 3 | -6 | 3 | 0 | P_{2} | |
c | ← | -3 | 3 | 0 | 0 | P_{3} | |
d | ← | 1 | 0 | 0 | 0 | P_{4} |
Homework due Wednesday April 30:
Optional things you can also try for extra credit: