Sunday, March 30, 2014

subdividing a cubic bezier curve

Another useful property of a cubic Bezier is that it can be perfectly subdivided into two smaller cubic splines at any point.

This is a change of variables, remapping the first segment {0..t} -> {0..1} and the second segment {t..1} -> {0..1}

For a cubic Bezier spline with control points P0, P1, P2, P3. We can evaluate a point on the curve with De Casteljau's algorithm:

Q0[t_] := P0 * (1 - t) + P1 *t
Q1[t_] := P1 * (1 - t) + P2 *t
Q2[t_] := P2 * (1 - t) + P3 *t

R0[t_] := Q0[t] * (1 - t) + Q1[t] * t
R1[t_] := Q1[t] * (1 - t) + Q2[t] * t

S0[t_] := R0[t] * (1 - t) + R1[t] * t

In the wikipedia graphics below S0 is shown as B.

Construction of a cubic Bézier curveAnimation of a cubic Bézier curve, t in [0,1]

We subdivide the curve into two segments at any value t.  The first segment will have control points P0, Q0[t], R0[t], S0[t].  The second will have control points S0[t], R1[t], Q2[t], P3.

Recursively subdividing the cubic spline with t=0.5 is a good numerically stable way of drawing these curves.  (The recursion is halted at the display resolution, or when the curve segment between the endpoints is sufficiently straight.)

No comments:

Post a Comment