Spline Interpolation - PowerPoint PPT Presentation

1 / 65
About This Presentation
Title:

Spline Interpolation

Description:

Local data changes have local effect. Continuous with ... Monomial basis. The coefficients do not give tangible geometric meaning. 29. Spline Interpolation ... – PowerPoint PPT presentation

Number of Views:213
Avg rating:3.0/5.0
Slides: 66
Provided by: abdennour8
Category:

less

Transcript and Presenter's Notes

Title: Spline Interpolation


1
  • Spline Interpolation

Abdennour El Rhalibi
2
Position Interpolation Problem
Generate a path through points at designated
times with smooth motion
3
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

4
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

5
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 the quantity is
  • Check that this satisfies all the requirements.
  • Note We only do this for t between 0 and 1,
    inclusive.

6
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
  • and proceed as before

7
Curves
Explicit form y f(x)
Implicit form 0 f(x,y)
x f(u)
Parametric form
y g(u)
8
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) Axa Bxb
  • Y(a) Aya Byb P(a) Axa
    Bx(1-a)
  • Z(a) Aza Bzb


9
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) Axa Bxb
  • Y(a) Aya Byb
  • Z(a) Aza Bzb
  • 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.

10
Linear interpolation
  • Curve continuity ?
  • Locality ?
  • Computational effort ?

11
Linear interpolation
  • Curve continuity ?
  • -- Low (C0)
  • Locality ?
  • Computational effort ?
  • P(a) Axa Bx(1-a), a ?0..1

Important Criteria Continuity is missing for
Linear Interpolation
12
Quadratic
  • Ok, now we have done lines, but what about
    curves?
  • (ab), where b (1.0-a) is the key.
  • We know that a polynomial function is a curve, so
    why not try to make (ab) a polynomial function?
  • Let's try
  • (ab)² a² 2ab b²
  • Knowing that b1-a we see that a² 2ab b² is
    still equal to one,
  • since (ab) 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) Axa² Bx2ab Cxb²
  • Y(a) Aya² By2ab Cyb²
  • Z(a) Aza² Bz2ab Czb²
  • P(a) Axa²
    Bx2a(1-a) Cx(1-a)²


13
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) Axa² Bx2ab Cxb²
  • Y(a) Aya² By2ab Cyb²
  • Z(a) Aza² Bz2ab Czb²
  • If you set a 0.5, then a² 0.25, 2ab 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, ab 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.

14
Polynomial interpolation
  • Curve continuity ?
  • Locality ?
  • Computational effort ?

15
Example Polynomial interpolation
  • Curve continuity ?
  • Locality ?
  • --
  • Computational effort ?
  • P(a) Axa² Bx2a(1-a) Cx(1-a)²

Important Criteria of Locality is missing for
Polynomial Interpolation
16
Cubic
  • We can also increase the number of control points
    using (ab)³ instead of (ab)², giving you more
    control over how to bend the curve.
  • (ab)³ a³ 3a²b 3ab² b³
  • Now we need four control points A, B, C and D,
    where A and D are the end points.
  • X(a) Axa³ Bx3a²b Cx3ab² Dxb³
  • Y(a) Aya³ By3a²b Cy3ab² Dyb³
  • Z(a) Aza³ Bz3a²b Cz3ab² Dzb³
  • 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.

17
Cubic
  • X(a) Axa³ Bx3a²b Cx3ab² Dxb³
  • Y(a) Aya³ By3a²b Cy3ab² Dyb³
  • Z(a) Aza³ Bz3a²b Cz3ab² Dzb³
  • You can easily use (ab) to the power of n and
    get n1 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 ?

18
Particle Motion
  • A curve in 3-dimensional space

World coordinates
19
Keyframing Particle Motion
  • Find a smooth function that passes
    through given keyframes

World coordinates
20
Polynomial Curve
  • Mathematical function vs. discrete samples
  • Compact
  • Resolution independence
  • Why polynomials ?
  • Simple
  • Efficient
  • Easy to manipulate
  • Historical reasons

21
Degree and Order
  • Polynomial
  • Order n1 ( number of coefficients)
  • Degree n

22
Polynomial Interpolation
  • Linear interpolation with a polynomial of degree
    1
  • This is a linear equation and coefficient
    are unknown
  • Lets write this in matrix form

23
Linear Interpolation
  • Linear interpolation equation in matrix form
  • If you multiply these you will get the equation
  • Now our unknowns are the coefficients stored in
    column vector C
  • We need to find these unknowns before we can do
    anything

24
Linear Interpolation
  • Lets rewrite C to this
  • This gives us final equation
  • M is called the basis function and G is the
    geometric constraints vector.
  • Which is our standard linear interpolation
    formula

25
Polynomial Interpolation
  • Quadratic interpolation with a polynomial of
    degree 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

26
Polynomial Interpolation
  • Polynomial interpolation of degree 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.
  • (n1) for degree n.

27
Spline Interpolation
  • Piecewise smooth curve
  • Low-degree (cubic for example) polynomial
  • Uniform vs. non-uniform knot sequences

Time
28
Basis Functions
  • A linear space of cubic polynomials
  • Monomial basis
  • The coefficients do not give tangible
    geometric meaning

29
Spline Interpolation
  • Piecewise smooth curve
  • Low-degree (cubic for example) polynomial
  • Uniform vs. non-uniform knot sequences
  • Again in Matrix form we have
  • So what is the geometric constraints vector and
    the basis function?
  • This depend on the application and splines form
    used

30
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
  • Lets see first Hermite Curve

31
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.

32
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)

33
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

34
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

35
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

36
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 x0
    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

37
Finding Hermite coefficients
  • And the solution is
  • a0 x0
  • a1 x0/
  • a2 -3x0 2x0/ 3x1 x1/
  • a3 2x0 x0/ - 2x1 x1/
  • h1(t) 2t3 - 3t2 1 -gt X0
  • h2(t) -2t3 3t2 -gt X1
  • h3(t) t3 - 2t2 t -gt X0
  • h4(t) t3 - t2 -gt X1
  • Hermite basis functions

H3
H4
H2
H1
38
The Hermite matrix MH
The resultant polynomial can be expressed in
matrix form
X(t) TTMHC ( C is the control
vector)
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

39
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. -h2 starts at 0 and
goes slowly to 1. Now multiply the startpoint
with h1 and the endpoint with h2.Let s go from 0
to 1 to interpolate between start and endpoint.
h3 and h4 are applied to the tangents in the
same manner.They make sure that the curve bends
in the desired direction at the start and
endpoint
x0
x1
h1
h2
x0/
h3
h4
x1/
40
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

41
Family of Hermite curves.
y(t)
Note Start points on left.
x(t)
42
Hermite splines
  • moveto (P1) // move
    pen to startpoint
  • for (int t0 t lt 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 h1P1 h2P2 h3T1 h4T2
  • // draw to calculated point on the curve
  • lineto (p)

PseudoCode
43
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

44
Bézier Curves
  • Hermite cubic curves are difficult to model
    need to specify point and gradient.
  • Its 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

45
Bézier Matrix
  • The cubic form is the most popular
  • X(t) TTMBC (MB is the Bézier matrix)
  • With n4 and r0,1,2,3 we get
  • Similarly for Y(t) and Z(t)

46
Bezier Curve
  • Bernstein basis functions
  • Cubic polynomial in Bernstein bases
  • Bezier Control points (control polygon)

47
Bézier blending functions
This is how they look The Convex Hull property
holds, ie. The functions sum to 1 at any point
along the curve. Endpoints have full weight The
weights of each function is clear and the labels
show the control points being weighted.
q0
q3
q1
q2
48
Properties of Bezier Curves
  • The curve is contained in the convex hull of the
    control polygon
  • The curve is invariant under affine
    transformation
  • Partition of unity of Bernstein basis functions
  • End point interpolation

49
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

50
Bézier Curves
Note the Convex Hull has been shown as a dashed
line use as a bounding extent for intersection
purposes.
P2
P4
P1
P3
P3
P4
P1
P2
51
Bezier Curve Versatility
  • This simple definition of 4 Points can be used to
    create many complex geometric figures

52
Bezier Splines with Tangent Conditions
  • Adobe Illustrator provides excellent user
    interfaces for cubic Bezier splines
  • Find a piecewise Bezier curve that passes through
    given keyframes and tangent vectors

53
Cardinal Splines
54
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 i1 P i-1)
  • Formula for tangents with a being a constant
    which affects the tightness of the curve.

55
Catmull-Rom splines
56
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)

57
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)
58
Catmull-Rom Splines
  • Polynomial interpolation without tangent
    conditions
  • -continuity

59
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?

60
Kochanek-Bartels Splines TCB
61
Kochanek-Bartels Splines TCB
62
Kochanek-Bartels Splines TCB
63
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

64
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

65
Comparison of Basic Cubic Splines
Write a Comment
User Comments (0)
About PowerShow.com