Spline Notes Marc Olano University of Maryland, Baltimore County February, 4 Introduction I. Modeled after drafting tool A. Thin strip of wood or metal B. Control smooth curved path by running between small weights or ducks Image from www.frets.com II. Graphics version = parametric curve: p(s) A. Control Points. Points in space that control spline s shape. Like ducks in drafting splines. Interpolating = spline passes through control points 3. Approximating = spline passes near but not necessarily through control points (most popular) B. Non-rational/ordinary: P(s) = vector of desired dimension ( ) X(s) D : P(s) = (X(s)); D : P(s) = ; 3D : P(s) = X(s) Y(s) Y(s) Z(s)
C. Rational: p(s) = homogeneous vector x(s) y(s) p(s) = z(s) z(s) where X Y = x/w y/w Z z/w D. Tangent, Normal, Binormal A. Tangent, ˆT = vector in direction of curve B. Normal, ˆN = vector normal to curve, in direction of greatest curvature. C. Binormal, ˆB = vector normal to curve, perpendicular to tangent and normal D. Define in terms of st and nd derivatives of curve: P (s) = X (s) Y (s) = velocity(s) ˆT(s) Z (s) P (s) = X (s) Y (s) = linearaccel(s) ˆT(s) + centripidalaccel ˆN(s) Z (s) E. Together, these make the Frenet Frame ˆT, ˆN, ˆB ) ˆT(s) = normalize( P (s) ) ˆB(s) = normalize( P (s) P (s) ˆN(s) = ˆB(s) ˆT(s) Polynomial splines I. About the only splines you will ever see. II. Most common in graphics: cubic (s 3 ) for general rendering, quintic (s 5 ) for CAD X(s) = as 3 + bs + cs+d = (a b c s d) s X (s) = 3as + bs+c = (a b c d) X (s) = 6as+b = (a b c d) III. Constraints s 3 3s s 6s = (a b c d) s = (a b c d) s = (a b c d) s
A. Degree n polynomial has n+ coefficients: as+b; as + bs+c; as 3 + bs + cs+d;... B. Solving for n+ unknown coefficients requires n+ constraints (so for cubic, you need 4) Typical types of constraints:. Pass through X i at s i X i = (a b c d) = (a b c d) s i s 3 i s i s i. Have derivative X i at s i X 3. Have nd derivative X i IV. Fitting many control points 3s i s i = (a b c d) i = (a b c d) s i X at s i i = (a b c d) = (a b c d) s i 6s i A. Global: fit with large system / high-degree polynomial. + Single curve. Every control point has some affect on the entire curve B. Piecewise: fit with many short curves, joined end-to-end. + Control points only affect local curve. Must use some constraints to keep joins smooth 3 Spline zoo I. Hermite A. Give position and derivatives at each endpoint 3
X, X at s = s = ; X, X at s = s = Use conditions of the form X() = X = as 3 + by + cs + d = d X() = X = as 3 + bs + cs + d = a+b+c+d X () = X = 3as + bs + c = c X () = X = 3as + bs + c = 3a+b+c Or in matrix form: (X X X X ) = (a b c d)( s s s s ) 3 = (a b c d) = (a b c d) H Even though X(s) is a polynomial in s, it is linear in a, b, c and d. Solve as linear equation! (a b c d) = (X X X X ) H 3 = (X X X X ) 3 B. Can reuse this matrix for any curve specified by value and derivatives at the endpoints C. Can also reuse the same matrix for each component of the curve: P(s) = X(s) Y(s) = Z(s) a X b X c X d X a Y b Y c Y d Y a Z b Z c Z d Z = ( A B C D) s s 3 s s a X b X c X d X a Y b Y c Y d Y = X X X X Y Y Y Y H a Z b Z c Z d Z Z Z Z Z ( A B C D) = ( P P P P ) H 4
II. Natural A. value, st and nd derivatives at s = match previous B. Even though segmented, each control point has global effect on all segments! C. Create single linear system to solve for coefficients of all curve segments. D. Natural because behavior is similar to drafting spline III. Interpolating A. To fit m points, need polynomial of degree n = m B. Single curve, each control point has global influence C. Example: fit four points with a cubic P at s = s =, P at s = s = 3, P at s = s = 3, and P 3 at s = s 3 = ( P P P P 3 ) = ( A B C D)( s s s s 3 ) 8 7 7 4 = ( A B C D) 9 9 3 3 = ( A B C D) M ( A B C D) = ( P P P P 3 ) M 9 9 7 = ( P P P P 3 ) 45 9 7 8 9 9 9 D. Basis functions Full spline equation is P(s) = ( P P P P 3 ) M s Grouping control points and matrix gives coefficients. 5
P(s) = [ ( P P P P 3 ) M ] s Grouping matrix and polynomial terms gives a polynomial basis functions for each control point. Total curve is a weighted average of the control points, with the weights given by the basis functions: P(s) = ( P P P P 3 ) [ M s ] f (s) f = ( P P P P 3 ) (s) f (s) f 3 (s) = P ( 9 s3 + 9s s+)+ P ( 7 s3 45 s + 9s)+ P ( 7 s3 + 8s 9 s)+ P 3 ( 9 s3 9 s + s) E. Here is a graph of these four basis functions IV. Catmull-Rom..8.6.4. -. -.4..4.6.8 A. Too hard to give derivatives, so derive them from control points. B. Endpoints P, P C. Derivatives ( P P ), ( P 3 P ) D. Chosen to pass through all points, match value and st derivative at st endpoint, and preserve local control E. Matrix (a b c d) = ( P P ( P P ) ( P 3 P )) H 6
Can use that equation as-is, or rearrange to find basis functions P(s) = ( P P ( P P ) ( P 3 P )) H s = ( P P P P 3 ) H s s3 + s s 3 s3 5 s + = ( P P P P 3 ) 3 s3 + s + s s 3 s V. Cardinal.8.6.4. -...4.6.8 A. Catmull-Rom is good, but not enough control B. Add tension parameter, τ to derivative terms C. Endpoints P, P D. Derivatives ( τ ) ( P P ), ( τ ) ( P 3 P ) E. τ = cusp < τ < sharper than Catmull-Rom τ = Catmull-Rom τ < flatter than Catmull-Rom F. Example with τ = and τ G. Matrix (a b c d) = ( P P τ ( P P ) τ ( P 3 P )) H 7
H. Basis functions: τ P(s) = ( P P τ ( P P ) ( P 3 P )) H s τ = ( P P P P 3 ) τ τ H s τ τ s 3 +( τ )s τ ( ) ) s τ = ( P P P P 3 ) s +( 3 τ 3 s + ( ) τ s 3 +(3 ( τ ))s + τ τ s 3 τ s I. Graph of basis functions for τ =, τ = s VI. Beziér A. Most common B. Endpoints P, P 3.8.6.4. C. Derivatives P P, P 3 P -...4.6.8 D. Match derivatives by choice of interior control points locations on successive segments E. Matrix (a b c d) = ( P P 3 P P P 3 P ) H F. Can also find points on Beziér curves using decastlejau s algorithm. To find the point /n of the way along the curve, find the points /n of the way between each pair of control points. Then find the point /n of the way between each 8
pair of points just found. Then find the point /n of the way between the two points just found. decastlejau s algorithm generalizes easily to Beziér curves of higher (or lower) degree than just cubic. Just iterate the successive subdivisions as many times as necessary until you get to a single point. G. Basis functions P(s) = ( P P 3 P P P 3 P ) H s = ( P P P P 3 ) H s s 3 s s+ s = ( P P P P 3 ) 3 s + s s 3 + s s 3 + s.8.6.4...4.6.8 These are known as the Bernstein basis functions. Beziér curves can be extended to any degree r polynomial using the n basis functions ( ) n B n,r (s) = t r r ( t) n r In terms of the Bernstein basis functions, the curve equation is P(s) = n i= P i B n,i (s) 4 Patches I. Create a rectangular patch by smoothly changing each control points of one spline curve along paths given by crossing set of spline curves. 9
II. The patch is symmetric in which direction you consider to be the control splines and which direction is the splines that sweep out the surface. ( P(s,t) = n i= m j= ) P i, j B n,i (s) B n, j (t) ) = n i= j=( m P i, j B n,i (s)b m, j (t) ) = m j= i=( n P i, j B n,i (s)b m, j (t) ( = m j= n i= ) P i, j B m, j (t) B n,i (s) III. P i, j is known as the control mesh IV. Render by subdividing (not covered here) or tessellating into polygons.