ppt

advertisement
Splines
Jehee Lee
Seoul National University
Particle Motion
• A curve in 3-dimensional space
p(t )  x(t ), y(t ), z(t )
World
coordinates
Keyframing Particle Motion
• Find a smooth function p(t ) that passes through
given keyframes (ti , pi ), 0  i  n.
(t1 , p1 )
(t3 , p3 )
(t0 , p 0 )
(t2 , p 2 )
World
coordinates
Polynomial Curve
• Mathematical function vs. discrete samples
– Compact
– Resolution independence
• Why polynomials ?
–
–
–
–
Simple
Efficient
Easy to manipulate
Historical reasons
x(t )  a x t 3  bx t 2  c x t  d x
y (t )  a y t 3  by t 2  c y t  d y
z (t )  a z t 3  bz t 2  c z t  d z
or
p(t )  at 3  bt 2  ct  d
Degree and Order
• Polynomial
– Order n+1 (= number of coefficients)
– Degree n
x(t )  ant  an1t
n
n 1
   a1t  a0
Polynomial Interpolation
• Linear interpolation with a polynomial of degree one
– Input: two nodes
– Output: Linear polynomial
(t1 , x1 )
a1t0  a0  x0
a1t1  a0  x1
(t0 , x0 )
x(t )  a1t  a0
1 t0  a0   x0 

    
1 t1  a1   x1 
Polynomial Interpolation
• Quadratic interpolation with a polynomial of degree two
(t1 , x1 )
a2t02  a1t0  a0  x0
a2t12  a1t1  a0  x1
(t2 , x2 )
(t0 , x0 )
x(t )  a2t  a1t  a0
2
a2t 22  a1t 2  a0  x2
1 t 0

1 t1
1 t
2

t02  a0   x0 
   
2
t1  a1    x1 
t 22  a2   x2 
Polynomial Interpolation
• Polynomial interpolation of degree n
(t1 , x1 )
(tn , xn )
(t0 , x0 )
x(t )  ant    a1t  a0
n
1

1


1

 t0n 1 t0n  a0   x0 
   
n 1
n
 t1
t1  a1   x1 
 




 
 
   
 tnn 1 t nn  an   xn 
Do we really need to
solve the linear system ?
Lagrange Polynomial
• Weighted sum of data points and cardinal
functions
x(t )  L0 (t ) x0  L1 (t ) x1    Ln (t ) xn
(t  t0 )  (t  t k 1 )(t  tk 1 )  (t  t n )
Lk (t ) 
(t k  t0 )  (tk  t k 1 )(t k  t k 1 )  (t k  t n )
• Cardinal polynomial functions
1 if k  i
Lk (ti )  
0 if k  i
Limitation of Polynomial Interpolation
• Oscillations at the ends
– Nobody uses higher-order polynomial interpolation now
• Demo
– Lagrange.htm
Spline Interpolation
• Piecewise smooth curves
– Low-degree (cubic for example) polynomials
– Uniform vs. non-uniform knot sequences
x3
x1
x2
x0
t0
t1
t2
xn
t3
tn
Time
Why cubic polynomials ?
• Cubic (degree of 3) polynomial is a lowestdegree polynomial representing a space curve
• Quadratic (degree of 2) is a planar curve
– Eg). Font design
• Higher-degree polynomials can introduce
unwanted wiggles
Interpolation and Approximation
Continuity Conditions
• To ensure a smooth transition from one section of a
piecewise parametric spline to the next, we can impose
various continuity conditions at the connection points
• Parametric continuity
– Matching the parametric derivatives of adjoining curve sections
at their common boundary
• Geometric continuity
– Geometric smoothness independent of parametrization
– parametric continuity is sufficient, but not necessary, for
geometric smoothness
Parametric Continuity
• Zero-order parametric continuity
– C 0-continuity
– Means simply that the curves meet
• First-order parametric continuity
– C 1-continuity
– The first derivatives of two adjoining
curve functions are equal
• Second-order parametric continuity
– C 2-continuity
– Both the first and the second
derivatives of two adjoining curve
functions are equal
Geometric Continuity
• Zero-order geometric continuity
– Equivalent to C 0-continuity
• First-order geometric continuity
– G1-continuity
– The tangent directions at the ends of two adjoining
curves are equal, but their magnitudes can be
different
• Second-order geometric continuity
– G 2-continuity
– Both the tangent directions and curvatures at the
ends of two adjoining curves are equal
Basis Functions
• A linear space of cubic polynomials
3 2 1 0
– Monomial basis (t , t , t , t )
x(t )  a3t  a2t  a1t  a0
3
2
– The coefficients ai do not give tangible geometric
meaning
Bezier Curve
• Bernstein basis functions
n
n i i


B (t )   (1  t ) t
i
n
i
B03 (t )  (1  t ) 3
B13 (t )  3t (1  t ) 2
B23 (t )  3t 2 (1  t )1
B33 (t )  t 3
• Cubic polynomial in Bernstein bases
p(t )  b 0 B03 (t )  b1B13 (t )  b 2 B23 (t )  b3 B33 (t )
 (1  t )3 b 0  3t (1  t ) 2 b1  3t 2 (1  t )b 2  t 3b3
Bernstein Basis Functions
Bezier Control Points
• Control points (control polygon)
• Demo
– Bezier.htm
b0 , b1 , b 2 , b3
Bezier Curves in Matrix Form
p(t )  b 0 B03 (t )  b1B13 (t )  b 2 B23 (t )  b3 B33 (t )
 (1  t )3 b 0  3t (1  t ) 2 b1  3t 2 (1  t )b 2  t 3b3
B03 (t )  (1  t ) 3
B13 (t )  3t (1  t ) 2
B23 (t )  3t 2 (1  t )1
B33 (t )  t 3
P(t )  T  M B  G
 1 3  3 1  b 0 
 3  6 3 0 b 
1 
3 2



 t t t 1
 3 3 0 0 b 2 

 
 1 0 0 0  b 3 


De Casteljau Algorithm
• Subdivision of a Bezier Curve into two curve
segments
Properties of Bezier Curves
• Invariance under affine transformation
– Partition of unity of Bernstein basis functions
• The curve is contained in the convex hull of the
control polygon
0  B (t )  1 if 0  t  1
n
i
• Variation diminishing
– the curve in 2D space does not oscillate about any
straight line more often than the control point polygon
Properties of Cubic Bezier Curves
• End point interpolation
p(0)  b 0
p(1)  b 3
• The tangent vectors to the curve at the end
points are coincident with the first and last edges
b0
of the control point polygon
p' (0)  3(b1  b 0 )
p' (1)  3(b 3  b 2 )
b3
b1
b2
Properties of Cubic Bezier Curves
Bezier Surfaces
• The Cartesian (tensor) product of Bernstein
basis functions
n
n
p(u, v)   b jk B nj (u )Bkn (v)
j 0 k 0
Bezier Surface in Matrix Form
n
n
p(u, v)   b jk B nj (u )Bkn (v)
j 0 k 0
 UT  M  G  M T  V
 1 3  3
 3 6 3
 u3 u2 u 1 
 3 3 0

 1 0 0


1  b00
0 b01
0 b02

0  b03
b10
b11
b12
b13
b20
b21
b22
b23
b30   1 3  3
b31   3  6 3
b32   3 3 0

b33   1 0 0
1  v 3 
 
0 v 2 
0  v 
 
0  1 
Bezier Splines with Tangent Conditions
• Find a piecewise Bezier curve that passes
through given keyframes and tangent vectors
(t1 , p1 )
(t3 , p3 )
(t0 , p 0 )
(t2 , p 2 )
• Adobe Illustrator provides a typical example of
user interfaces for cubic Bezier splines
Catmull-Rom Splines
• Polynomial interpolation without tangent conditions
– C 1-continuity
– Local controllability
p i 1  p i 1
p' (ti ) 
2
(t1 , p1 )
(t0 , p 0 )
• Demo
– CatmullRom.html
(t3 , p3 )
(t2 , p 2 )
Natural Cubic Splines
• Is it possible to achieve higher continuity ?
– C n 1 -continuity can be achieved from splines of
degree n
• Motivated by loftman’s spline
– Long narrow strip of wood or plastic
– Shaped by lead weights (called ducks)
Natural Cubic Splines
• We have 4n unknowns
– n Bezier curve segments (4 control points per each segment)
• We have (4n-2) equations
– 2n equations for end point interpolation
– (n-1) equations for tangential continuity
– (n-1) equations for second derivative continuity
• Two more equations are required !
(t1 , x1 )
(t3 , x3 )
(tn1 , xn1 )
(t0 , x0 )
(t2 , x2 )
(tn , xn )
Natural Cubic Splines
• Natural spline boundary condition
x(t0 )  x(tn )  0
• Closed boundary condition
x(t0 )  x(tn ) and
x(t0 )  x(tn )
• High-continuity, but no local controllability
• Demo
– natcubic.html
– natcubicclosed.html
B-splines
• Is it possible to achieve both C 2-continuity and
local controllability ?
– B-splines can do !
– But, B-splines do not interpolate any of control points
• Uniform cubic B-spline basis functions
3
p(t )   b j B 3j (t )
j 0
 b 0 B03 (t )  b1 B13 (t )  b 2 B23 (t )  b 3 B33 (t )
1
B03 (t )  (1  t )3
6
1
B13 (t )  (3t 3  6t 2  4)
6
1
B23 (t )  (3t 3  3t 2  3t  1)
6
1
B33 (t )  t 3
6
B-Splines in Matrix Form
p(t )  b 0 B03 (t )  b1B13 (t )  b 2 B23 (t )  b3 B33 (t )
 (1  t )3 b 0  3t (1  t ) 2 b1  3t 2 (1  t )b 2  t 3b3
P (t )  T  M B  G
1
B03 (t )  (1  t )3
6
1
B13 (t )  (3t 3  6t 2  4)
6
1
B23 (t )  (3t 3  3t 2  3t  1)
6
1
B33 (t )  t 3
6
 1 3  3 1   p0 
 3  6 3 0  p 
1
1 
3 2


 t t t 1
6   3 0 3 0  p2 

 
 1 4 1 0   p3 


Uniform B-spline basis functions
• Bell-shaped basis function for each control
points
• Overlapping basis functions
– Control points correspond to knot points
B-spline Properties
•
•
•
•
•
Convex hull
Affine invariance
Variation diminishing
C 2-continuity
Local controllability
• Demo
– Bspline.html
NURBS
n
• Non-uniform Rational B-splines
– Non-uniform knot spacing
– Rational polynomial
p(t ) 
n

b
B
 j j j (t )
j 0
n
 B
j 0
j
• A polynomial divided by a polynomial
• Can represent conics (circles, ellipses, and hyperbolics)
• Invariant under projective transformation
• Note
– Uniform B-spline is a special case of non-uniform B-spline
– Non-rational B-spline is a special case of rational B-spline
n
j
(t )
Cubic Spline Interpolation in a B-Spline Form
Conversion Between
Spline Representations
• Sometimes it is desirable to be able to switch from one
spline representation to another
• For example, both B-spline and Bezier curves represent
polynomials, so either can be used to go from one to the
other
P (t )  T  M 1  G1
 T  M 2  G2
• The conversion matrix is
M 1  G1  M 2  G2
G2  M 21  M 1  G1
Displaying Spline Curves
• Forward-difference calculation
– Generate successive values recursively by
incrementing previously calculated values
– For example, consider a cubic polynomial
x(t )  at 3  bt 2  ct  d
– We want to calculate x(t) at tk for k=0,1,2,…
tk 1  tk  
Displaying Spline Curves
• Forward-difference calculation
– Two successive values of a cubic polynomial
xk (t )  at  bt  ctk  d
3
k
2
k
xk 1 (t )  a(tk   )  b(tk   )  c(tk   )  d
3
2
– The forward difference is a quadratic polynomial with
respect to t
xk (t )  xk 1 (t )  xk (t )
 3at  (3a  2b )tk  (a  b  c )
2
k
2
3
2
Displaying Spline Curves
• Forward-difference calculation
– The second- and third-order forward difference
2 xk (t )  xk 1 (t )  xk (t )
 6a 2t k  6a 3  2b 2
3 xk (t )  2 xk 1 (t )  2 xk (t )
 6a 3
– Incremental evaluation of polynomial
xk 1 (t )  xk (t )  xk (t )
 xk (t )  xk 1 (t )  2 xk 1 (t )
 xk (t )  xk 1 (t )  2 xk 2 (t )  3 xk 2 (t )
Matrix Equations for B-splines
1
B03 (t )  (1  t )3
6
1
B13 (t )  (3t 3  6t 2  4)
6
1
B23 (t )  (3t 3  3t 2  3t  1)
6
1
B33 (t )  t 3
6
• Cubic B-spline curves
p(t )  p 0 B03 (t )  p1 B13 (t )  p 2 B23 (t )  p 3 B33 (t )
p 0 
p 
 B03 (t ) B13 (t ) B23 (t ) B33 (t )  1 
p 2 
 
p 3 
4
1 0 p 0 
p 0 
1
p 
 3 0
 p 
3
0
1
1

    1 t t2 t3 M  1 
 1 t t2 t3
p 2 
6  3  6 3 0 p 2 
 

 
p

1
3

3
1
Monomial Bases 
  3
p 3 





Geometric Matrix
Control Points

Curve Refinement
• Subdivide a curve into two segments
•
Figures and equations were taken from
http://graphics.idav.ucdavis.edu/education/CAGDNotes/homepage.html
Binary Subdivision
• The left segment
t
P (t )  P( )
2
L
 t  t  2  t 3 
 1
    
 2  2   2  

 1 t t2
1
0

t3 
0

0


0
1
2
0
0
p 0 
p 
M  1
p 2 
 
p 3 
0
0
1
4
0
0  p 
0

0  p 
 1
M
0  p 2 
  
1  p 3 
8
Binary Subdivision

P L (t )  1 t t 2

 1 t t2
1
0

t 3 MM 1 
0

0

p 0L 
 L
p1 
3

t M L
p 2 
 L
p 3 


0
1
2
0
0
0
0
1
4
0
0  p 
0

0  p 
 1
M
0  p 2 
  
1  p 3 
8
Binary Subdivision
The Subdivision Rule for Cubic B-Splines
• The new control polygon consists of
– Edge points: the midpoints of the line segments
– Vertex points: the weighted average of the
corresponding vertex and its two neighbors
Recursive Subdivision
• Recursive subdivision brings the control polygon to
converge to a cubic B-spline curve
• Control polygon + subdivision rule
– Yet another way of defining a smooth curve
Chaikin’s Algorithm
• Corner cutting (non-stationary subdivision)
• Converges to a quadratic B-spline curve
• Demo: subdivision.htm
Interpolating Subdivision
• The original control points are interpolated
– Vertex points: The original control points
– Edge points: The weighed average of the original points
• Stationary subdivision
• Demo: subdivision.htm
Subdivision Surfaces
• bi-cubic uniform B-spline patch can be
subdivided into four subpatches
Catmull-Clark Surfaces
• Generalization of the bi-cubic B-spline
subdivision rule for arbitrary topological meshes
Catmull-Clark Surfaces
Subdivision in Action
• A Bug’s Life
Subdivision in Action
• Geri’s Game
Summary
• Polynomial interpolation
– Lagrange polynomial
• Spline interpolation
– Piecewise polynomial
– Knot sequence
– Continuity across knots
• Natural spline ( C 2-continuity)
• Catmull-Rom spline ( C 1-continuity)
– Basis function
• Bezier
• B-spline
Download