interpolating curves - department of computer science · interpolating curves. university of texas...
TRANSCRIPT
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
Interpolating curves
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 2
Reading
OptionalBartels, Beatty, and Barsky. An Introduction toSplines for use in Computer Graphics andGeometric Modeling, 1987. (See coursereader.)
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
Parametric curve review
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 4
Parametric curvesWe use parametric curves, Q(u)=(x(u),y(u)),where x(u) and y(u) are cubic polynomials:
Advantages:easy (and efficient) to compute“well behaved”infinitely differentiable
We also assume that u varies from 0 to 1
HGuFuEuuy
DCuBuAuux
+++=
+++=
23
23
)(
)(
))0(),0(( yx))1(),1(( yx
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 5
Various ways to set A,B,C,D
0) Directly – non-intuitive; not very useful.1) Set positions and derivatives of endpoints: “Hermite Curve”2) Use “control points” that indirectly influence the curve:
“Bezier curve”: - interpolates endpoints - does not interpolate middle control points
“B-spline” - does not interpolate ANY control points
DCuBuAuux +++=23)(
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 6
Splines = join cubic curves
ConsiderationsWhat kind of continuity at join points (“knots”)?
C0 = valueC1 = first derivativeC2 = second derivative
How do control points work?
B-spline
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 7
Spline summary
Joined Hermite curves:C1 continuityInterpolates control points
B-splines:C2 continuityDoes not interpolate control points
Can we get…C2 continuityInterpolates control points
That’s what we’ll talk about towardsthe end of this lecture.But first, some other useful tips.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
Useful tips for Bézier curves
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 9
Displaying Bézier curvesHow could we draw one of these things?
It would be nice if we had an adaptive algorithm, thatwould take into account flatness.
DisplayBezier( V0, V1, V2, V3 )begin if ( FlatEnough( V0, V1, V2, V3 ) ) Line( V0, V3 ); else something;end;
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 10
Subdivide and conquer
DisplayBezier( V0, V1, V2, V3 )
begin if ( FlatEnough( V0, V1, V2, V3 ) ) Line( V0, V3 ); else Subdivide(V[]) ⇒ L[], R[] DisplayBezier( L0, L1, L2, L3 ); DisplayBezier( R0, R1, R2, R3 );end;
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 11
Testing for flatness
Compare total length of control polygon tolength of line connecting endpoints:
!
V0"V
1+ V
1"V
2+ V
2"V
3
V0"V
3
<1+ #
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
Tips for B-splines
B-spline:- C2 continuity- does not interpolate any ctrl points
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 13
Endpoints of B-splinesWe can see that B-splines don’t interpolate the controlpoints.It would be nice if we could at least control the endpointsof the splines explicitly.There’s a trick to make the spline begin and end at controlpoints by repeating them.In the example below, let’s force interpolation of the lastendpoint: (use endpoint 3 times)
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
Tips for animator project
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 15
What if we want a closed curve, i.e., a loop?With Catmull-Rom and B-spline curves,this is easy:
Closing the loop
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
C2 interpolating curves
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 17
Simple interpolating splines
Join several Hermite curves:- Make derivatives match- You still have ability to pick what that matched derivative is.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 18
Cardinal splinesIf we set each derivative to be some positive scalar multiple k of thevector between the previous and next controls, we get a Cardinalspline.This leads to:
for any two consecutive interior points pi and pi+1 (we can deal withthe endpoints separately if need be)
Think of τ as a parameter that controls the tension of the spline
!
pi
u= "(p
i+1 #pi#1)
pi+1
u= "(p
i+2 #pi)
τ(p2-p0)
τ(p3-p1)
τ(p4-p2)
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 19
Cardinal splines
!
p(u) = u3
u2
u 1[ ]
2 "2 1 1
"3 3 "2 "1
0 0 1 0
1 0 0 0
#
$
% % % %
&
'
( ( ( (
pi
pi+1
pi
u
pi+1
u
#
$
% % % %
&
'
( ( ( (
= u3
u2
u 1[ ]
2 "2 1 1
"3 3 "2 "1
0 0 1 0
1 0 0 0
#
$
% % % %
&
'
( ( ( (
pi
pi+1
) pi+1 "pi"1( )
) pi+2 "pi( )
#
$
% % % %
&
'
( ( ( (
= u3
u2
u 1[ ]
2 "2 1 1
"3 3 "2 "1
0 0 1 0
1 0 0 0
#
$
% % % %
&
'
( ( ( (
0 1 0 0
0 0 1 0
") 0 ) 0
0 ") 0 )
#
$
% % % %
&
'
( ( ( (
pi"1
pi
pi+1
pi+2
#
$
% % % %
&
'
( ( ( (
= u3
u2
u 1[ ] )
"1 2 /) "1 "2 /) +1 1
2 "3/) +1 3/) " 2 "1
"1 0 1 0
0 1/) 0 0
#
$
% % % %
&
'
( ( ( (
pi"1
pi
pi+1
pi+2
#
$
% % % %
&
'
( ( ( (
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 20
Catmull-Rom splinesIf we set τ = 1/2, we get a Catmull-Rom spline.So:
for any two consecutive interior points pi and pi+1 (again dealing withendpoints separately as needed)
!
p(u) = u3
u2
u 1[ ] "
#1 2 /" #1 #2 /" +1 1
2 #3/" +1 3/" # 2 #1
#1 0 1 0
0 1/" 0 0
$
%
& & & &
'
(
) ) ) )
pi#1
pi
pi+1
pi+2
$
%
& & & &
'
(
) ) ) )
= u3
u2
u 1[ ]1
2
#1 3 #3 1
2 #5 4 #1
#1 0 1 0
0 2 0 0
$
%
& & & &
'
(
) ) ) )
pi#1
pi
pi+1
pi+2
$
%
& & & &
'
(
) ) ) )
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 21
Catmull-Rom blending functions
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 22
C2 interpolating splinesHow can we keep the C2 continuity we get with B-splinesbut get interpolation, too?Again start with connected cubic curves.Each cubic segment is an Hermite curve for which we getto set the position and derivative of the endpoints.That leaves us with a spline that’s C0 and C1 such as aCatmull-Rom or Cardinal spline.But interestingly, there are other ways to choose the valuesof the (shared) first derivatives at the join points.Is there a way to set those derivatives to get other usefulproperties?
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 23
Find second derivativesSo far, we have:
C0, C1 continuity Derivatives are still free, as ‘D0…D4’
Compute second derivatives at both sidesof every join point:
For p1:For p2:…
!
" " Q 0(1) = 6p0 # 6p1 + 2D0 + 4D1 " " Q 1(0) = #6p1 + 6p2 # 4D1 # 2D2
" " Q 1(1) = 6p1 # 6p2 + 2D1 + 4D2" " Q 2(0) = #6p2 + 6p3 # 4D2 # 2D3
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 24
Match the second derivatives
Now, symbolically set the second derivatives tobe equal.For p1
For p2
…!
6p0 " 6p1 + 2D0 + 4D1 = "6p1 + 6p2 " 4D1 " 2D2
3(p2 "p0) =D0 + 4D1 +D2
!
6p1 " 6p2 + 2D1 + 4D2 = "6p2 + 6p3 " 4D2 " 2D3
3(p3 "p1) =D1 + 4D2 +D3
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 25
Not quite done yet
How many equations is this? m-1How many unknowns are we solving for? m+1We have two additional degrees of freedom, which we cannail down by imposing more conditions on the curve.There are various ways to do this. We’ll use the variantcalled natural C2 interpolating splines, which requiresthe second derivative to be zero at the endpoints.This condition gives us the two additional equations weneed.
At the P0 endpoint, it is:At the Pm endpoint, we have:
''
0 (0) 0Q =''
1(1) 0mQ
!=
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 26
Solving for the derivatives
Let’s collect our m+1 equations into a single linearsystem:
It’s easier to solve than it looks.See the notes from Bartels, Beatty, and Barsky fordetails.
!
2 1
1 4 1
1 4 1
O
1 4 1
1 2
"
#
$ $ $ $ $ $ $
%
&
' ' ' ' ' ' '
D0
T
D1
T
D2
T
M
Dm(1T
Dm
T
"
#
$ $ $ $ $ $ $
%
&
' ' ' ' ' ' '
=
3 p1(p
0( )T
3 p2(p
0( )T
3 p3(p
1( )T
M
3 pm(p
m(2( )T
3 pm(p
m(1( )T
"
#
$ $ $ $ $ $ $ $
%
&
' ' ' ' ' ' ' '
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 27
C2 interpolating spline
Once we’ve solved for the real Dis, we can plugthem in to find our Bézier or Hermite curves anddraw the final spline:
Have we lost anything?=> Yes, local control.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 28
Next time: Subdivision curves
Basic idea:Represent a curve as an iterative
algorithm, rather than as an explicit function.Reading:
• Stollnitz, DeRose, and Salesin. Wavelets for Computer Graphics: Theory and Applications, 1996, section 6.1-6.3, A.5. [Course reader pp. 248-259 and pp. 273-274]