As we known that a cubic spline curve
with control points a_{0 }, a_{1 }, a_{2 },
a_{3 } can be subdivided in two sub curves with control points
b_{0 }, b_{1 }, b_{2 }, b_{3 } and
c_{0 }, c_{1 }, c_{2 }, c_{3 }
as shown to the left
function subdiv(a0,a1,a2,a3){ var b1 = av(a0,a1), a12 = av(a1,a2), b2 = av(b1, a12), c2 = av(a2,a3), c1 = av(a12,c2), b3 = av(b2,c1); return [[a0,b1,b2,b3],[b3,c1,c2,a3]]; } function av(v1, v2){ return [.5*(v1[0]+v2[0]), .5*(v1[1]+v2[1]), .5*(v1[2]+v2[2])]; }where av(v1, v2) is the midpoint between v1 and v2. |
This algorithm is simple but not very accurate. E.g. for eps = 0.1 you can see small holes between quads with different sizes (and subdivision orders).