Document Sample

Spline Interpolation Abdennour El Rhalibi 1 Position Interpolation Problem Generate a path through points at designated times with smooth motion 2 Interpolation Qualities • Want smooth curves • Local control – Local data changes have local effect • Continuous with respect to the data – No wiggling if data changes slightly • Low computational effort 3 Continuity • Describe curves in terms of their continuity in a segment and between segments • Parametric continuity Cx – Only P is continuous: C0 • Positional continuity – P and first derivative are continuous: C1 • Tangential continuity – P + first + second: C2 • Curvature continuity 4 Linear Interpolation: Simple Case • When we lirp, we are given two values of a quantity; we determine its value somewhere between these. – To do this, we assume that the graph of the quantity is a line segment (between the two given values). • Here is a simple case: – When t = 0, the quantity is equal to a. – When t = 1, the quantity is equal to b. – Given a value of t between 0 and 1, the interpolated value of 1 t a t b. the quantity is – Check that this satisfies all the requirements. – Note: We only do this for t between 0 and 1, inclusive. 5 Linear Interpolation: General Case • What if we are not given values of the quantity at 0 and 1? – Say the value at s1 is a and the value at s2 is b, and we want to find the interpolated value at s. – We set s s1 t , s2 s1 – and proceed as before: ed_value 1 t a t b. interpolat 6 Curves Explicit form: y = f(x) Implicit form: 0 = f(x,y) x = f(u) Parametric form: y = g(u) 7 Simple line • The simplest form of interpolation is a straight line from a control point A, to a control point B. • I will use Ax to denote the x-coordinate of control point A, and Ay to denote the y-coordinate. • The same goes for B. • I am introducing another variable, b, just to make it a bit more simple to read the functions. • However, the variable b is only a in disguise, b is always equal to 1-a. • So if a = 0.2, then b = 1-0.2 = 0.8. So when you see the variable b, think: (1-a). • This parametric curve describes a line that goes from point A, to point B when the variable a goes from 1.0 to 0.0: } • X(a) = Ax·a + Bx·b • Y(a) = Ay·a + By·b P(a) = Ax·a + Bx·(1-a) • Z(a) = Az·a + Bz·b 8 Simple line • This parametric curve describes a line that goes from point A, to point B when the variable a goes from 1.0 to 0.0: • X(a) = Ax·a + Bx·b • Y(a) = Ay·a + By·b • Z(a) = Az·a + Bz·b • If you set a = 0.5 • (and thus also b = 0.5, since b = 1.0-a = 1.0-0.5 = 0.5) • then X(a), Y(a) and Z(a) will give you the 3D coordinate of the point on the middle of the line from point A to point B. • • Note that the reason this works is because a + b is always equal to one, and when you multiply something with one, it will stay unchanged. • This makes the curve behave predictably and lets you place the control points anywhere in the coordinate system, since when a = 1.0 then b = 0.0 thus making the point equal to one of the control points, and completely ignoring the other one. 9 Linear interpolation • Curve continuity ? • Locality ? • Computational effort ? 10 Linear interpolation • Curve continuity ? – -- Low (C0) • Locality ? – + • Computational effort ? – ++ – P(a) = Ax·a + Bx·(1-a), a [0..1] Important Criteria Continuity is missing for Linear Interpolation 11 Quadratic • Ok, now we have done lines, but what about curves? (a+b), where b = (1.0-a) is the key. • We know that a polynomial function is a curve, so why not try to make (a+b) a polynomial function? • Let's try: • (a+b)² = a² + 2a·b + b² • Knowing that b=1-a we see that a² + 2·a·b + b² is still equal to one, • since (a+b) = 1, and 1² = 1. • We now need three control points, A, B and C, where A and C are the end points of the curve, and B decides how much and in which direction it curves. • Except for that, it is the same as with the parametric line. • X(a) = Ax·a² + Bx·2·a·b + Cx·b² • Y(a) = Ay·a² + By·2·a·b + Cy·b² • Z(a) = Az·a² + Bz·2·a·b + Cz·b² } P(a) = Ax·a² + Bx·2·a·(1-a) + Cx·(1- a)² 12 Quadratic This parametric curve describes a curve that goes from point A, to point C in the direction of C when the variable a goes from 1.0 to 0.0: • X(a) = Ax·a² + Bx·2·a·b + Cx·b² • Y(a) = Ay·a² + By·2·a·b + Cy·b² • Z(a) = Az·a² + Bz·2·a·b + Cz·b² • If you set a = 0.5, then a² = 0.25, 2·a·b = 0.5 and • b² = 0.25 giving the middle point, B, the biggest impact and making point A and C pull equally to their sides. • If you set a = 1.0, then a² = 1.0, a·b = 0.0 and b² = 0.0 meaning that result is the control point A itself, • Just the same as setting a = 0.0 will return the coordinates of control point C. 13 Polynomial interpolation • Curve continuity ? • Locality ? • Computational effort ? 14 Example: Polynomial interpolation • Curve continuity ? – ++ • Locality ? – -- • Computational effort ? – + – P(a) = Ax·a² + Bx·2·a·(1-a) + Cx·(1-a)² Important Criteria of Locality is missing for Polynomial Interpolation 15 Cubic • We can also increase the number of control points using (a+b)³ instead of (a+b)², giving you more control over how to bend the curve. • (a+b)³ = a³ + 3·a²·b + 3·a·b² + b³ • Now we need four control points A, B, C and D, where A and D are the end points. • X(a) = Ax·a³ + Bx·3·a²·b + Cx·3·a·b² + Dx·b³ • Y(a) = Ay·a³ + By·3·a²·b + Cy·3·a·b² + Dy·b³ • Z(a) = Az·a³ + Bz·3·a²·b + Cz·3·a·b² + Dz·b³ • It still works the same way as the previous ones, as a goes from 1.0 to 0.0 (and thus b from 0.0 to 1.0) the functions will return coordinates on a smooth line from control point A to control point D, curving towards B and C on the way. 16 Cubic • X(a) = Ax·a³ + Bx·3·a²·b + Cx·3·a·b² + Dx·b³ • Y(a) = Ay·a³ + By·3·a²·b + Cy·3·a·b² + Dy·b³ • Z(a) = Az·a³ + Bz·3·a²·b + Cz·3·a·b² + Dz·b³ • You can easily use (a+b) to the power of n and get n+1 control points (where n is any integer equal to, or greater than one). • But the more control points you have, the more computational effort is needed. • Personally I like the cubic ones best. You can easily make circles with them, and you can control the direction of the curve independently at each control point. • Curve continuity ? • ++ • Locality ? • - • Computational effort ? 17 • + Particle Motion • A curve in 3-dimensional space p(t ) x(t ), y(t ), z(t ) World coordinates 18 Keyframing Particle Motion • Find a smooth function p(t ) that passes through given keyframes (ti , pi ), 0 i n. (t1 , p1 ) (t0 , p 0 ) (t3 , p 3 ) (t2 , p 2 ) World coordinates 19 Polynomial Curve • Mathematical function vs. discrete samples – Compact – Resolution independence • Why polynomials ? x(t ) a x t 3 bx t 2 c x t d x – Simple – Efficient y (t ) a y t 3 by t 2 c y t d y – Easy to manipulate – Historical reasons z (t ) a z t 3 bz t 2 c z t d z or p(t ) at 3 bt 2 ct d 20 Degree and Order • Polynomial – Order n+1 (= number of coefficients) – Degree n n 1 x(t ) ant an1t n a1t a0 21 Polynomial Interpolation • Linear interpolation with a polynomial of degree 1 a1t0 a0 x0 (t1 , x1 ) a1t1 a0 x1 (t0 , x0 ) 1 t0 a0 x0 1 t a x x(t ) a1t a0 1 1 1 (eq.1) 0 t 1 • This is a linear equation and coefficient a1 and a0 are unknown • Let’s write this in matrix form… 22 Linear Interpolation • Linear interpolation equation in matrix form (t1 , x1 ) (t0 , x0 ) a0 C a 1 x(t ) a1t a0 (eq.1) x(t ) T .C T (1 t) • If you multiply these you will get the equation (eq.1) • Now our unknowns are the coefficients stored in column vector C • We need to find these unknowns before we can do anything… 23 Linear Interpolation • Let’s rewrite C to this: C M. G • This gives us final equation x(t ) T .M .G • M is called the basis function and G is the geometric constraints vector. 1 1 T (t 1) 1 0 M P G 1 P2 x(t ) T .M .G x(t ) (t * 1 1*1) * P1 (t ) * P 2 (1 t ) * P1 (t ) * P 2 • Which is our standard linear interpolation formula… 24 Polynomial Interpolation • Quadratic interpolation with a polynomial of degree 2 a2t0 a1t0 a0 x0 2 (t1 , x1 ) a2t12 a1t1 a0 x1 a2t 2 a1t 2 a0 x2 2 (t2 , x2 ) (t0 , x0 ) 1 t 0 t0 a0 x0 2 1 t1 t1 a1 x1 2 1 t t 2 a2 x2 x(t ) a2t a1t a0 2 2 2 • Curves are just a generalisation of the previous approach • The only thing that changes in deriving the formula is that there are more geometric constraints. – 3 for quadratic – 4 for Cubic 25 Polynomial Interpolation • Polynomial interpolation of degree n 1 t0 t0 a0 x0 2 (t1 , x1 ) 1 t1 t1 a1 x1 2 1 2 t n an xn (tn , xn ) (t0 , x0 ) tn x(t ) ant a1t a0 n • Curves are just a generalisation of the previous approach • The only thing that changes in deriving the formula is that there are more geometric constraints. – (n+1) for degree n. 26 Spline Interpolation • Piecewise smooth curve – Low-degree (cubic for example) polynomial – Uniform vs. non-uniform knot sequences x1 x3 x0 x2 xn t0 t1 t2 t3 t4 Time 27 Basis Functions • A linear space of cubic polynomials – Monomial basis (t 3 , t 2 , t 1 , t 0 ) x(t ) a3t a2t a1t a0 3 2 – The coefficients ai do not give tangible geometric meaning 28 Spline Interpolation • Piecewise smooth curve – Low-degree (cubic for example) polynomial – Uniform vs. non-uniform knot sequences x(t ) a3t 3 a2t 2 a1t a0 0 t 1 • Again in Matrix form we have x(t ) T .M .G T [t 3 t 2 t 1] • So what is the geometric constraints vector and the basis function? • This depend on the application and splines form used… 29 Spline curves • Many different types • Some are better for interpolation – Others – for geometric modeling • We will study: – Hermite interpolation – Catmull-Rom Splines – Blended parabolas – Bezier curves • Other types: – Splines with tension – B-splines – NURBS • Let’s see first Hermite Curve… 30 Hermite Curve Interpolation • The curve is controlled by a start point, end point and tangent vectors at the start and end-points of the curve. • The curve passes through the start and end point and the tangent vectors control the velocity and the direction at the start and end points. • The whole story of parametric splines is in deriving their coefficients. • How we do that, by satisfying constraints set by the knots and continuity conditions (C0, C1, C2), is what classifies the spline system and distinguishes the different systems. 31 Hermite splines • Hermite curves are very easy to calculate but also very powerful. • They are used to smoothly interpolate between key- points (like object movement in keyframe animation or camera control). • Understanding the mathematical background of hermite curves will help you to understand the entire family of splines : – Cardinal Splines – Catmull-Rom Splines – Bezier – Kochanek-Bartels Splines (also known as TCB- Splines) 32 Hermite splines • To calculate a hermite curve you need the following vectors: – P1: the startpoint of the curve – T1: the tangent (e.g. direction and speed) to how the curve leaves the startpoint – P2: he endpoint of the curve – T2: the tangent (e.g. direction and speed) to how the curves meets the endpoint 33 Hermite splines • These 4 vectors are simply multiplied with 4 hermite basis functions and added together. • h1(t) = 2t3 - 3t2 + 1 • h2(t) = -2t3 + 3t2 • h3(t) = t3 - 2t2 + t • h4(t) = t3 - t2 • Hermite basis functions 34 Hermite splines • 4 degrees of freedom, 2 at each end to control C0 and C1 continuity at each end. • Polynomial can be specified by the position of, and gradient at, each endpoint of curve. • Determine: x = X(t) in terms of x0, x0/, x1, x1/ Now: X(t) = a3t3 + a2t2 + a1t + a0 and X/(t) = 3a3t2 + 2a2t + a1 35 Finding Hermite coefficients Substituting for t at each endpoint: x0 = X(0) = a0 x0/ = X/(0) = a1 x1 = X(1) = a3 + a2 + a1 + a0 x1/ = X/(1) = 3a3 + 2a2+ a1 And the solution is: a0 = x 0 a1 = x0/ a2 = -3x0 – 2x0/ + 3x1 – x1/ a3 = 2x0 + x0/ - 2x1 + x1/ h1(t) = 2t3 - 3t2 + 1 h2(t) = -2t3 + 3t2 h3(t) = t3 - 2t2 + t h4(t) = t3 - t2 Hermite basis functions 36 Finding Hermite coefficients And the solution is: a0 = x 0 H3 H2 H4 a1 = H1 x0 / a2 = -3x0 – 2x0/ + 3x1 – x1/ a3 = 2x0 + x0/ - 2x1 + x1/ h1(t) = 2t3 - 3t2 + 1 -> X0 h2(t) = -2t3 + 3t2 -> X1 h3(t) = t3 - 2t2 + t -> X0’ h4(t) = t3 - t2 -> X1’ Hermite basis functions 37 The Hermite matrix: MH The resultant polynomial can be expressed in matrix form: X(t) = TTMHC ( C is the control vector) 2 1 2 1 x0 3 2 3 1 x / X (t ) t 3 t 2 t 1 0 1 0 0 0 x1 / 1 0 0 0 x1 T H C We can now define a parametric polynomial for each coordinate required independently, ie. X(t), Y(t) and Z(t) To calculate a point on the curve you build the vector T, multiply it with the matrix H and then multiply with C 38 Hermite Basis (Blending) Functions The graph shows the shape of the four basis functions – often called blending functions. Take a closer look at functions h1 and h2: - h1 starts at 1 and goes slowly to 0. x0 x1 -h2 starts at 0 and goes slowly to 1. h1 h2 Now multiply the startpoint with h1 and the endpoint with h2. Let s go from 0 to 1 to interpolate between start and endpoint. x0/ h3 and h4 are applied to the tangents in the h3 same manner. They make sure that the curve bends in the x1/ h4 desired direction at the start and endpoint 39 Displaying Hermite curves. • Simple : – Loop through t – select step size to suit. – Plug x values into the geometry matrix. – Evaluate P(t) x value for current position. – Repeat for y & z independently. – Draw line segment between current and previous point. • Joining curves: – Coincident endpoints for C0 continuity – Align tangent vectors for C1 continuity 40 Family of Hermite curves. y(t) Note : Start points on left. x(t) 41 Hermite splines • moveto (P1); // move pen to startpoint • for (int t=0; t < steps; t++) • { float s = (float)t / (float)steps; // scale s to go from 0 to 1 • float h1 = 2s3 - 3s2 + 1; // calculate basis function 1 • float h2 = -2s3 + 3s2; // calculate basis function 2 • float h3 = s3 - 2s2 + s; // calculate basis function 3 • float h4 = s3 - s2; // calculate basis function 4 • // multiply and sum all functions • // together to build the interpolated point along the curve. • vector p = h1*P1 + h2*P2 + h3*T1 + h4*T2; • // draw to calculated point on the curve • lineto (p) • } PseudoCode 42 Why cubic polynomials ? • Cubic (degree of 3) polynomial is a lowest-degree polynomial representing a space curve • Quadratic (degree of 2) is a planar curve – Eg). Font design • Higher-degree polynomials can introduce unwanted wiggles 43 Bézier Curves • Hermite cubic curves are difficult to model – need to specify point and gradient. • It’s hard to guess what a curve will look like using the tangents • It is more intuitive to only specify points. • Bézier curves specified 2 endpoints and 2 additional control points to specify the gradient at the endpoints. • Can be derived from Hermite matrix: – Two end control points specify tangent 44 Bézier Matrix • The cubic form is the most popular • X(t) = TTMBC (MB is the Bézier matrix) • With n=4 and r=0,1,2,3 we get: 1 3 3 1 q0 3 6 0 q1 X (t ) t 3 t 2 t 1 3 3 3 0 0 q2 1 0 0 0 q3 • Similarly for Y(t) and Z(t) 45 Bezier Curve • Bernstein basis functions B0 (t ) (1 t ) 3 3 B13 (t ) 3t (1 t ) 2 n B (t ) (1 t ) n i t i i n i B2 (t ) 3t 2 (1 t )1 3 B3 (t ) t 3 3 • Cubic polynomial in Bernstein bases p(t ) b 0 B0 (t ) b1B13 (t ) b 2 B2 (t ) b3 B3 (t ) 3 3 3 (1 t ) b 0 3t (1 t )2b1 3t (1 t )b 2 t b 3 3 2 3 • Bezier Control points (control polygon) b0 , b1 , b 2 , b3 46 Bézier blending functions This is how they look – The Convex Hull property holds, ie. The functions q0 q3 sum to 1 at any point along the curve. q1 q2 Endpoints have full weight The weights of each function is clear and the labels show the control points being weighted. 47 Properties of Bezier Curves • The curve is contained in the convex hull of the control polygon 0 B (t ) 1 if 0 t 1 3 0 • The curve is invariant under affine transformation – Partition of unity of Bernstein basis functions • End point interpolation p(0) b 0 p(1) b 3 48 Properties of Cubic Bezier Curves • The tangent vectors to the curve at the end points are coincident with the first and last edges of the control point polygon 1 p' (0) (b1 b 0 ) 3 1 p' (1) (b 3 b 2 ) 3 49 Bézier Curves Note the Convex Hull has been shown as P2 a dashed line – use as a bounding extent for intersection purposes. P4 P1 P3 P3 P4 P1 P2 50 Bezier Curve Versatility • This simple definition of 4 Points can be used to create many complex geometric figures 51 Bezier Splines with Tangent Conditions • Find a piecewise Bezier curve that passes through given keyframes and tangent vectors (t1 , p1 ) (t3 , p 3 ) (t0 , p 0 ) (t2 , p 2 ) • Adobe Illustrator provides excellent user interfaces for cubic Bezier splines 52 Cardinal Splines 53 Cardinal Splines • Cardinal splines are just a subset of the hermite curves. • They don't need the tangent points because they will be calculated from the control points. • We'll lose some of the flexibility of the hermite curves, but as a tradeoff the curves will be much easier to use. • Ti = a* (P i+1 – P i-1) • Formula for tangents with a being a constant which affects the tightness of the curve. 54 Catmull-Rom splines 55 Catmull-Rom splines • Catmull-Rom spline interpolates control points. The gradient at each control point is the vector between adjacent control points. • The Catmull-Rom spline is again just a subset of the cardinal splines. • You only have to define a as 0.5, and you can draw and interpolate Catmull-Rom splines. • Tangent information is derived from data points • At the ends: • User provides tangents • Tangent directed towards P_1-(P_2-P_1) 1 Pi ' (u ) ( Pi 1 Pi 1 ) 2 56 Catmull-Rom splines Catmull-Rom spline interpolates control points. The gradient at each control point is the vector between adjacent control points. The resultant polynomial can be expressed in matrix form: X(t) = 0.5 * TTMHC ( C is the control vector) P i (t ) T M CR GB 1 3 3 1 Pi 3 2 5 4 1 P 1 i 2 T 2 1 0 1 0 Pi 1 0 2 0 0 Pi 57 Catmull-Rom Splines • Polynomial interpolation without tangent conditions – C 1-continuity p i 1 p i 1 p' (ti ) (t1 , p1 ) 2 (t0 , p 0 ) (t3 , p 3 ) (t2 , p 2 ) 58 Kochanek-Bartels Splines: TCB • The kb-splines (mostly known from 3d-Studio Max) are nothing more than Hermite curves and a handfull of formulas to calculate the tangents. • These curves have been introduced by D. Kochanek and R. Bartels in 1984 to give animators more control over keyframe animation. • They introduced three control-values for each keyframe point: – Tension: How sharply does the curve bend? – Continuity: How rapid is the change in speed and direction? – Bias: What is the direction of the curve as it passes through the keypoint? 59 Kochanek-Bartels Splines: TCB 60 Kochanek-Bartels Splines: TCB 61 Kochanek-Bartels Splines: TCB 62 Finer curve shape controls • Can adjust the shape by playing with tangent values – Direction fixed • Splines with tension t: apply scaling to tangent vector – Low tension = greater tangents = flatter connections = curve farther from straight line – High tension = smaller tangents = sharper connection = curve closer to straight line • Sometimes want to break continuity • Can change tangent directions – Continuity parameter c – Allows to change how the far are two tangents • Sometimes want to bias tangent to favor one of the sides – Bias parameter b 63 Finer curve shape controls • Put all three (t,c,b) together: • Can use these wherever tangents are needed • Default (0,0,0) gives Catmull-Rom spline 64 Comparison of Basic Cubic Splines 65

DOCUMENT INFO

Shared By:

Categories:

Tags:

Stats:

views: | 23 |

posted: | 9/1/2011 |

language: | English |

pages: | 65 |

OTHER DOCS BY yaofenji

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.