# Cubic Bezier 4-point Interpolation Part II

I finished the basic version of the demo, but it’s evident that several aspects require some discussion.  I don’t have time for a full TechNote, so I’ll go over each issue in a separate blog post.  This will make it a lot easier to understand the code.

To review, the problem is as follows.  Given four vectors, V0, V1, V2, and V3, find the control points, P0, P1, P2, and P3 of a cubic Bezier curve, B(t), so that the curve passes through V0, V1, V2, and V3.  The first decision is how to parameterize the curve.  In other words, what are the parameter values of B(t) at each of the interpolation points?  Uniform parameterziation makes the following assignments.

B(0) = V0, B(1/3) = V1, B(2/3) = V2, B(1) = V3.

In fact, any parameterization would have B(0) = V0 and B(1) = V3, so the two ‘interesting’ parameter values are B(t1) = V1 and B(t2) = V2.  It’s helpful to have an automatic means for selecting these parameter values and uinform parmeterization is the easiest approach.

An alternative, which is better if you do not require precise velocity control along the curve, is chord-length parameterization.  It is a bit more expensive to compute, but that is not an issue if the curve is parameterized once and then sprites are animated along the curve over and over.

Let d1 = d(V0,V1), where d(a,b) is the Euclidean distance between vectors a and b.  Let d2 = d(V1,v2) and d3 = d(V2,V3).  If d = d1 + d2 + d3, then select t1 = d1/d and t2 = (d1+d2)/d.  This method selects parameter values that are proportional to the cumulative distance along the chords from vector to vector.

It should be evident that P0 = V0 and P3 = V3, so the problem reduces to computing P1 and P2.  There are four unknowns; the x- and y-coordinates of P1 and P2.  To solve, we need four equations.  The parameter values come into play here.  The equation for B(t) is evaluated at t1 and t2 and set equal to V1 and V2, respectively.  Since the parameter values are known, this yields two vector equations (or four scalar equations).  The derivation of these equations will be presented tomorrow.

Advertisement