CMSC427 Parametric curves: Hermite, Catmull-Rom, Bezier · 2017-12-05 · Parametric curves:...
Transcript of CMSC427 Parametric curves: Hermite, Catmull-Rom, Bezier · 2017-12-05 · Parametric curves:...
CMSC427Parametriccurves:Hermite,Catmull-Rom,Bezier
Modeling
• Creating3Dobjects• Howtoconstructcomplicatedsurfaces?• Goal• Specifyobjectswithfewcontrolpoints• Resultingobjectshouldbevisuallypleasing(smooth)
• Startwithcurves,thengeneralizetosurfaces
2
Usefulness of curves
• Surfaceofrevolution
3
Usefulness of curves
• Extruded/sweptsurfaces
4
Usefulness of curves
• Animation• Providea“track”forobjects• Useascamerapath
5
Usefulness of curves
• Generalizetosurfacepatchesusing“gridsofcurves”,nextclass
6
How to represent curves
• Specifyeverypointalongcurve?• Hardtogetprecise,smoothresults• Toomuchdata,toohardtoworkwith
• Idea:specifycurvesusingsmallnumbersofcontrolpoints• Mathematics:usepolynomials torepresent curves
Control point
7
Interpolating polynomial curves
http://en.wikipedia.org/wiki/Polynomial_interpolation
• Curvegoesthroughallcontrolpoints• Seemsmostintuitive• Surprisingly,notusuallythebestchoice• Hardtopredictbehavior• Overshoots,wiggles• Hardtoget“nice-looking”curves
Control point
Interpolating curve8
Approximating polynomial curves• Curveis“influenced”bycontrolpoints
• Varioustypes&techniquesbasedonpolynomialfunctions• Bézier curves,B-splines,NURBS
• FocusonBézier curves
Control point
9
Mathematical definition
• Avectorvaluedfunctionofonevariablex(t)• Givent,computea3Dpointx=(x,y,z)• Mayinterpretasthreefunctions x(t), y(t), z(t)• “Movingapointalongthecurve”
x
y
z
x(0.0) x(0.5) x(1.0)
x(t)
10
Tangent vector
• Derivative• Avectorthatpointsinthedirectionofmovement• Lengthofx’(t) correspondstospeed
x’(0.0) x’(0.5) x’(1.0)
x(t)
x
y
z
11
Piecewise polynomial curves• Modelcomplexshapesbysequence• Usepolylinetostorecontrolpoints
12
Continuity• Howpiecewisecurvesjoin• Ck continuity– kthderivativesmatch• Gk continuity– kthderivativesareproportional
13
• Cubiccurve(here2D)
𝑥 𝑡 = 𝑎𝑡3 + 𝑏𝑡6 + 𝑐𝑡 + 𝑑𝑦 𝑡 = 𝑒𝑡3 + 𝑓𝑡6 + 𝑔𝑡 + ℎ
• InterpolatesendpointsP0andP1• MatchestangentatendpointsT0andT1• (alsodP0anddP1inthesenotes).
Hermite curves
P0=(x0,y0)
P1 = (x1,y1)T1=<dx1,dy1>
T0=<dx0,dy0>
• Derivativeofx(t)
𝑥′ 𝑡 = 3𝑎𝑡6 + 2𝑏𝑡 + 𝑐• Sett=0and1forendpoints• Fourconstraints
𝑥 0 = 𝑑𝑥′(0) = 𝑐
𝑥 1 = 𝑎 + 𝑏 + 𝑐 + 𝑑𝑥′ 1 = 3𝑎 + 2𝑏 + 𝑐
Computing coefficients a, b, c and d
• Solvefora,b,candd𝑑 = 𝑥0
𝑐 = 𝑑𝑥0
𝑏 = −3𝑥0 + 3𝑥1 − 2𝑑𝑥0 − 𝑑𝑥1
𝑎 = 2𝑥0 − 2𝑥1 + 𝑑𝑥0 + 𝑑𝑥1
Solve for a, b, c and d
• Constraints𝑥 0 = 𝑑𝑥′(0) = 𝑐
𝑥 1 = 𝑎 + 𝑏 + 𝑐 + 𝑑𝑥′ 1 = 3𝑎 + 2𝑏 + 𝑐
• Give
0 0 0 11 1 1 10 0 1 03 2 1 0
𝑎𝑏𝑐𝑑=
𝑥0𝑥1𝑑𝑥0𝑑𝑥1
Matrix version
• Sincewehave𝑀𝐴 = 𝐺• Wecansolvewith𝐴 = 𝑀\]𝐺• AndgetHermite basismatrix𝑀\]
𝑎𝑏𝑐𝑑=
2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0
𝑥0𝑥1𝑑𝑥0𝑑𝑥1
Solve matrix version: basis matrix
• Toincludex,yandz,rewritewithvectorsP0,P1andtangentsT0andT1
𝒂𝒃𝒄𝒅
=
2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0
𝑷𝟎𝑷𝟏𝑻𝟎𝑻𝟏
• Coefficientsa,b,canddarenowvectors
Vector version
• Rewritepolynomialasdotproduct
𝑃 𝑡 = 𝑡3 𝑡6 𝑡 1
𝒂𝒃𝒄𝒅
•
= 𝑡3 𝑡6 𝑡 1
2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0
𝑷𝟎𝑷𝟏𝑻𝟎𝑻𝟏
Full polynomial version
• Insteadofpolynomialint,lookatcurveasweightedsumofP0,P1,T0andT1• 𝑥 𝑡 = 2𝑥0 − 2𝑥1 + 𝑑𝑥0 + 𝑑𝑥1 𝑡3
•+ −3𝑥0 + 3𝑥1 − 2𝑑𝑥0 − 𝑑𝑥1 𝑡6
•+ 𝑑𝑥0 𝑡
•+𝑥0
Blending functions
• Insteadofpolynomialint,lookatcurveasweightedsumofP0,P1,T0andT1
• 𝑥 𝑡 =• 2𝑡3 − 3𝑡6 + 1 𝑥0• + −2𝑡3 + 3𝑡6 𝑥1• + 𝑡3 − 2𝑡6 + 𝑡 𝑑𝑥0• + 𝑡3 − 𝑡6 𝑑𝑥1
Blending functions
•
ℎ00(𝑡) = 2𝑡3 − 3𝑡6 + 1ℎ01(𝑡) = −2𝑡3 + 3𝑡6
ℎ10(𝑡) = 𝑡3 − 2𝑡6 + 𝑡ℎ11(𝑡) = 𝑡3 − 𝑡6
Blending functions
• HaveP(-1),P0,P1andP2asinput• ComputetangentwithHmatrix
𝑥0𝑥1𝑑𝑥0𝑑𝑥1
=
1 0 0 00 1 0 0−1 1 0 00 0 −1 1
𝑥o𝑥]𝑥\]𝑥6
Computing Hermite tangents
• Unifynotation𝑎𝑏𝑐𝑑=
2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0
1 0 0 00 1 0 01 0 −1 00 −1 0 1
𝑥o𝑥]𝑥\]𝑥6
• Finalmatrix
•𝑎𝑏𝑐𝑑=
3 −3 −1 1−5 4 2 −11 0 −1 01 0 0 0
𝑥o𝑥]𝑥\]𝑥6
Combine with Hermite basis
• Hermite – problemwithC1continuity
Catmull-Rom curves
P0
P1
P2
P3
P4
P5left right
• Catmull-Rom– maketangentsymmetric• Definebytwoadjacentpoints• HereT3=P4-P2
Catmull-Rom curves
P0
P1
P2
P3
P4
P5
• NeedtochangeHmatrix• ½traditionalforC-Rcurves
𝑥0𝑥1𝑑𝑥0′𝑑𝑥1′
=
1 0 0 00 1 0 0
1/2 0 −1/2 0−1/2 0 0 1/2
𝑥o𝑥]𝑥\]𝑥6
Catmull-Rom curves
• Whichgives
𝑎𝑏𝑐𝑑=
2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0
1 0 0 00 1 0 0
1/2 0 −1/2 0−1/2 0 0 1/2
𝑥o𝑥]𝑥\]𝑥6
• Or𝑎𝑏𝑐𝑑=
2 −2 −0.5 0.5−3.5 3 1 −0.50.5 0 0.5 01 0 0 0
𝑥o𝑥]𝑥\]𝑥6
Catmull-Rom curves
Bézier curves
http://en.wikipedia.org/wiki/B%C3%A9zier_curve
• Aparticularlyintuitivewaytodefinecontrolpointsforpolynomialcurves• DevelopedforCAD(computeraideddesign)andmanufacturing• Beforegames,beforemovies,CADwasthebigapplicationforCG
• PierreBézier (1962),designofautobodiesforPeugeot,http://en.wikipedia.org/wiki/Pierre_B%C3%A9zier
• PauldeCasteljau (1959),forCitroen
30
Bézier curves
• Higherorderextensionoflinearinterpolation• Controlpointsp0, p1, ...
p0
p1
p0
p1p2
p0
p1
p2
p3
Linear Quadratic Cubic31
Bézier curves
• Intuitivecontrolovercurvegivencontrolpoints• Endpointsareinterpolated,intermediatepointsareapproximated• ConvexHullproperty• Variation-diminishingproperty
32
Cubic Bézier curve
• Cubicpolynomials,mostcommoncase• Definedby4controlpoints• Twointerpolatedendpoints• Twomidpoints controlthetangentattheendpoints
p1
p0 p2
p3
x(t)•
Control polyline
33
Bézier Curve formulation
• Threealternatives,analogoustolinearcase1. Weightedaverageofcontrolpoints2. Cubicpolynomialfunctionoft3. Matrixform• Algorithmicconstruction• deCasteljaualgorithm
34
de Casteljau Algorithm
http://en.wikipedia.org/wiki/De_Casteljau's_algorithm
• Arecursive seriesoflinearinterpolations• Worksforanyorder,notonlycubic
• Notterriblyefficienttoevaluate• Otherformsmorecommonlyused
• Whystudyit?• Intuitionaboutthegeometry• Usefulforsubdivision(latertoday)
35
de Casteljau Algorithm
p0
p1
p2
p3
• Giventhecontrolpoints• Avalueoft• Heret≈0.25
36
de Casteljau Algorithm
p0
q0
p1
p2
p3
q2
q1
q0 (t) = Lerp t,p0 ,p1( )q1(t) = Lerp t,p1,p2( )q2 (t) = Lerp t,p2 ,p3( )
37
de Casteljau Algorithm
q0
q2
q1
r1
r0
r0 (t) = Lerp t,q0 (t),q1(t)( )r1(t) = Lerp t,q1(t),q2 (t)( )
38
de Casteljau Algorithm
r1x
r0 •
x(t) = Lerp t,r0 (t),r1(t)( )
39
x•
p0
p1
p2
p3
de Casteljau algorithm
•Applets• http://www2.mat.dtu.dk/people/J.Gravesen/cagd/decast.html• http://www.caffeineowl.com/graphics/2d/vectorial/bezierintro.html
40
de Casteljau Algorithm
http://en.wikipedia.org/wiki/De_Casteljau's_algorithm
Linear Quadratic
Cubic Quartic
41
x = Lerp t,r0 ,r1( )r0 = Lerp t,q0,q1( )r1 = Lerp t,q1,q2( )
q0 = Lerp t,p0 ,p1( )q1 = Lerp t,p1,p2( )q2 = Lerp t,p2 ,p3( )
p0p1p2p3
p1q0
r0 p2x q1
r1 p3q2
p4
Recursive linear interpolation
42
x = Lerp t,r0 ,r1( )r0 = Lerp t,q0,q1( )r1 = Lerp t,q1,q2( )
q0 = Lerp t,p0 ,p1( )q1 = Lerp t,p1,p2( )q2 = Lerp t,p2 ,p3( )
p0p1p2p3
p1q0
r0 p2x q1
r1 p3q2
p4
Recursive linear interpolation
43
x = Lerp t,r0 ,r1( )r0 = Lerp t,q0,q1( )r1 = Lerp t,q1,q2( )
q0 = Lerp t,p0 ,p1( )q1 = Lerp t,p1,p2( )q2 = Lerp t,p2 ,p3( )
p0p1p2p3
p1q0
r0 p2x q1
r1 p3q2
p4
Recursive linear interpolation
44
x = Lerp t,r0 ,r1( )r0 = Lerp t,q0,q1( )r1 = Lerp t,q1,q2( )
q0 = Lerp t,p0 ,p1( )q1 = Lerp t,p1,p2( )q2 = Lerp t,p2 ,p3( )
p0p1p2p3
p1q0
r0 p2x q1
r1 p3q2
p4
Recursive linear interpolation
45
Expand the LERPs
q0 (t) = Lerp t,p0 ,p1( )= 1- t( )p0 + tp1
q1(t) = Lerp t,p1,p2( )= 1- t( )p1 + tp2
q2 (t) = Lerp t,p2 ,p3( )= 1- t( )p2 + tp3
r0 (t) = Lerp t,q0 (t),q1(t)( )= 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )r1(t) = Lerp t,q1(t),q2 (t)( )= 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )
x(t) = Lerp t,r0 (t),r1(t)( )= 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( ) +t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
46
Expand the LERPs
q0 (t) = Lerp t,p0 ,p1( )= 1- t( )p0 + tp1
q1(t) = Lerp t,p1,p2( )= 1- t( )p1 + tp2
q2 (t) = Lerp t,p2 ,p3( )= 1- t( )p2 + tp3
r0 (t) = Lerp t,q0 (t),q1(t)( )= 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )r1(t) = Lerp t,q1(t),q2 (t)( )= 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )
x(t) = Lerp t,r0 (t),r1(t)( )= 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( ) +t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
47
Expand the LERPs
q0 (t) = Lerp t,p0 ,p1( )= 1- t( )p0 + tp1
q1(t) = Lerp t,p1,p2( )= 1- t( )p1 + tp2
q2 (t) = Lerp t,p2 ,p3( )= 1- t( )p2 + tp3
r0 (t) = Lerp t,q0 (t),q1(t)( )= 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )r1(t) = Lerp t,q1(t),q2 (t)( )= 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )
x(t) = Lerp t,r0 (t),r1(t)( )= 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( ) +t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
48
Expand the LERPs
q0 (t) = Lerp t,p0 ,p1( )= 1- t( )p0 + tp1
q1(t) = Lerp t,p1,p2( )= 1- t( )p1 + tp2
q2 (t) = Lerp t,p2 ,p3( )= 1- t( )p2 + tp3
r0 (t) = Lerp t,q0 (t),q1(t)( )= 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )r1(t) = Lerp t,q1(t),q2 (t)( )= 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )
x(t) = Lerp t,r0 (t),r1(t)( )= 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( ) +t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
49
Expand the LERPs
q0 (t) = Lerp t,p0 ,p1( )= 1- t( )p0 + tp1
q1(t) = Lerp t,p1,p2( )= 1- t( )p1 + tp2
q2 (t) = Lerp t,p2 ,p3( )= 1- t( )p2 + tp3
r0 (t) = Lerp t,q0 (t),q1(t)( )= 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )r1(t) = Lerp t,q1(t),q2 (t)( )= 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )
x(t) = Lerp t,r0 (t),r1(t)( )= 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( ) +t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
50
!
x(t) = 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( )+t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
x(t) = 1- t( )3 p0 + 3 1- t( )2 tp1 + 3 1- t( )t 2p2 + t 3p3
x(t) = -t 3 + 3t 2 - 3t +1( )B0 (t )" #$$$ %$$$
p0 + 3t 3 - 6t 2 + 3t( )B1 (t )" #$$ %$$
p1+ -3t 3 + 3t 2( )
B2 (t )& '$ ($
p2 + t 3( )B3 (t ))p3
Weighted average of control points• Regroup
51
!
x(t) = 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( )+t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
x(t) = 1- t( )3 p0 + 3 1- t( )2 tp1 + 3 1- t( )t 2p2 + t 3p3
x(t) = -t 3 + 3t 2 - 3t +1( )B0 (t )" #$$$ %$$$
p0 + 3t 3 - 6t 2 + 3t( )B1 (t )" #$$ %$$
p1+ -3t 3 + 3t 2( )
B2 (t )& '$ ($
p2 + t 3( )B3 (t ))p3
Weighted average of control points• Regroup
52
!
x(t) = 1- t( ) 1- t( ) 1- t( )p0 + tp1( )+ t 1- t( )p1 + tp2( )( )+t 1- t( ) 1- t( )p1 + tp2( )+ t 1- t( )p2 + tp3( )( )
x(t) = 1- t( )3 p0 + 3 1- t( )2 tp1 + 3 1- t( )t 2p2 + t 3p3
x(t) = -t 3 + 3t 2 - 3t +1( )B0 (t )" #$$$ %$$$
p0 + 3t 3 - 6t 2 + 3t( )B1 (t )" #$$ %$$
p1+ -3t 3 + 3t 2( )
B2 (t )& '$ ($
p2 + t 3( )B3 (t ))p3
Weighted average of control points• Regroup
Bernsteinpolynomials53
• Partitionofunity,ateacht alwaysaddto1• Endpointinterpolation,B0 andB3 goto 1
x(t) = B0 t( )p0 + B1 t( )p1 + B2 t( )p2 + B3 t( )p3
The cubic Bernstein polynomials :
B0 t( )= -t 3 + 3t 2 - 3t +1
B1 t( )= 3t 3 - 6t 2 + 3t
B2 t( )= -3t 3 + 3t 2
B3 t( )= t 3
Bi (t) = 1å
Cubic Bernstein polynomials
http://en.wikipedia.org/wiki/Bernstein_polynomial
54
General Bernstein polynomials
B01 t( )= -t +1 B0
2 t( )= t 2 - 2t +1 B03 t( )= -t 3 + 3t 2 - 3t +1
B11 t( )= t B1
2 t( )= -2t 2 + 2t B13 t( )= 3t 3 - 6t 2 + 3t
B22 t( )= t 2 B2
3 t( )= -3t 3 + 3t 2
B33 t( )= t 3
Bin t( )=
ni
æèçöø÷
1- t( )n- i t( )ini
æèçöø÷=
n!i! n - i( )!
Bin t( )å = 1
55
General Bernstein polynomials
B01 t( )= -t +1 B0
2 t( )= t 2 - 2t +1 B03 t( )= -t 3 + 3t 2 - 3t +1
B11 t( )= t B1
2 t( )= -2t 2 + 2t B13 t( )= 3t 3 - 6t 2 + 3t
B22 t( )= t 2 B2
3 t( )= -3t 3 + 3t 2
B33 t( )= t 3
Bin t( )=
ni
æèçöø÷
1- t( )n- i t( )ini
æèçöø÷=
n!i! n - i( )!
Bin t( )å = 1
56
General Bernstein polynomials
B01 t( )= -t +1 B0
2 t( )= t 2 - 2t +1 B03 t( )= -t 3 + 3t 2 - 3t +1
B11 t( )= t B1
2 t( )= -2t 2 + 2t B13 t( )= 3t 3 - 6t 2 + 3t
B22 t( )= t 2 B2
3 t( )= -3t 3 + 3t 2
B33 t( )= t 3
Bin t( )=
ni
æèçöø÷
1- t( )n- i t( )ini
æèçöø÷=
n!i! n - i( )!
Bin t( )å = 1
57
General Bernstein polynomials
B01 t( )= -t +1 B0
2 t( )= t 2 - 2t +1 B03 t( )= -t 3 + 3t 2 - 3t +1
B11 t( )= t B1
2 t( )= -2t 2 + 2t B13 t( )= 3t 3 - 6t 2 + 3t
B22 t( )= t 2 B2
3 t( )= -3t 3 + 3t 2
B33 t( )= t 3
Bin t( )=
ni
æèçöø÷
1- t( )n- i t( )ini
æèçöø÷=
n!i! n - i( )!
Bin t( )å = 1
Partitionofunity,endpointinterpolation
Ordern:
58
General Bézier curves
• nth-orderBernsteinpolynomialsformnth-orderBéziercurves• Béziercurvesareweightedsumofcontrolpointsusingnth-orderBernsteinpolynomials
Bin t( )=
ni
æèçöø÷1- t( )n- i t( )i
x t( )= Bin t( )pi
i=0
n
å
Bernsteinpolynomialsof ordern:
Béziercurve of ordern:
59
Bézier curve properties
• Convexhullproperty• Variationdiminishingproperty• Affineinvariance
60
Convex hull, convex combination
• Convexhullofasetofpoints• Smallestpolyhedralvolumesuchthat(i)allpointsareinit(ii)lineconnectinganytwopointsinthevolumeliescompletelyinsideit(oronitsboundary)
• Convexcombinationofthepoints• Weightedaverageofthepoints,whereweightsallbetween0 and
1,sumupto1• Anyconvexcombinationalwayslieswithintheconvexhull
p0
p1
p2
Convex hullp3
61
Convex hull property
• Bézier curveisaconvexcombinationofthecontrolpoints• Bernsteinpolynomialsaddto1ateachvalueoft
• Curveisalwaysinsidetheconvexhullofcontrolpoints• Makescurvepredictable• Allowsefficientculling,intersectiontesting,adaptivetessellation
p0
p1
p2
p3
62
Variation diminishing property
• Ifthecurveisinaplane,thismeansnostraightlineintersectsaBézier curvemoretimesthanitintersectsthecurve'scontrolpolyline• “Curveisnotmorewigglythancontrolpolyline”
Yellowline:7intersectionswithcontrolpolyline3intersectionswithcurve 63
Affine invariance
• TwowaystotransformBézier curves1. Transformthecontrolpoints,thencomputeresulting
pointoncurve2. Computepointoncurve,thentransformit
• Eitherway,getthesametransformpoint!• Curveisdefinedviaaffinecombinationofpoints(convexcombinationisspecialcaseofanaffinecombination)• Invariantunderaffinetransformations• Convexhullpropertyalwaysremains
64
• Goodforfastevaluation,precomputeconstantcoefficients(a,b,c,d)• Notmuchgeometricintuition
Start with Bernstein form:
x(t) = -t 3 + 3t 2 - 3t +1( )p0 + 3t 3 - 6t 2 + 3t( )p1 + -3t 3 + 3t 2( )p2 + t 3( )p3
Regroup into coefficients of t :x(t) = -p0 + 3p1 - 3p2 + p3( )t 3 + 3p0 - 6p1 + 3p2( )t 2 + -3p0 + 3p1( )t + p0( )1
x(t) = at 3 + bt 2 + ct + d
a = -p0 + 3p1 - 3p2 + p3( )b = 3p0 - 6p1 + 3p2( )c = -3p0 + 3p1( )d = p0( )
Cubic polynomial form
65
• Goodforfastevaluation,precomputeconstantcoefficients(a,b,c,d)• Notmuchgeometricintuition
Start with Bernstein form:
x(t) = -t 3 + 3t 2 - 3t +1( )p0 + 3t 3 - 6t 2 + 3t( )p1 + -3t 3 + 3t 2( )p2 + t 3( )p3
Regroup into coefficients of t :x(t) = -p0 + 3p1 - 3p2 + p3( )t 3 + 3p0 - 6p1 + 3p2( )t 2 + -3p0 + 3p1( )t + p0( )1
x(t) = at 3 + bt 2 + ct + d
a = -p0 + 3p1 - 3p2 + p3( )b = 3p0 - 6p1 + 3p2( )c = -3p0 + 3p1( )d = p0( )
Cubic polynomial form
66
• Goodforfastevaluation,precomputeconstantcoefficients(a,b,c,d)• Notmuchgeometricintuition
Start with Bernstein form:
x(t) = -t 3 + 3t 2 - 3t +1( )p0 + 3t 3 - 6t 2 + 3t( )p1 + -3t 3 + 3t 2( )p2 + t 3( )p3
Regroup into coefficients of t :x(t) = -p0 + 3p1 - 3p2 + p3( )t 3 + 3p0 - 6p1 + 3p2( )t 2 + -3p0 + 3p1( )t + p0( )1
x(t) = at 3 + bt 2 + ct + d
a = -p0 + 3p1 - 3p2 + p3( )b = 3p0 - 6p1 + 3p2( )c = -3p0 + 3p1( )d = p0( )
Cubic polynomial form
67
• Goodforfastevaluation,precomputeconstantcoefficients(a,b,c,d)• Notmuchgeometricintuition
Start with Bernstein form:
x(t) = -t 3 + 3t 2 - 3t +1( )p0 + 3t 3 - 6t 2 + 3t( )p1 + -3t 3 + 3t 2( )p2 + t 3( )p3
Regroup into coefficients of t :x(t) = -p0 + 3p1 - 3p2 + p3( )t 3 + 3p0 - 6p1 + 3p2( )t 2 + -3p0 + 3p1( )t + p0( )1
x(t) = at 3 + bt 2 + ct + d
a = -p0 + 3p1 - 3p2 + p3( )b = 3p0 - 6p1 + 3p2( )c = -3p0 + 3p1( )d = p0( )
Cubic polynomial form
68
• CanconstructothercubiccurvesbyjustusingdifferentbasismatrixB
• Hermite,Catmull-Rom,B-Spline,…
!
x(t) = "a"b "c déë ùû
t 3
t 2
t1
é
ë
êêêê
ù
û
úúúú
"a = -p0 + 3p1 - 3p2 + p3( )"b = 3p0 - 6p1 + 3p2( )"c = -3p0 + 3p1( )d = p0( )
x(t) = p0 p1 p2 p3[ ]
GBez
# $%%% &%%%
-1 3 -3 13 -6 3 0-3 3 0 01 0 0 0
é
ë
êêêê
ù
û
úúúú
BBez
# $%%% &%%%
t 3
t 2
t1
é
ë
êêêê
ù
û
úúúú
T'
Cubic matrix form
69
Cubic matrix form
xx (t) = p0x p1x p2x p3x[ ]
-1 3 -3 13 -6 3 0-3 3 0 01 0 0 0
é
ë
êêêê
ù
û
úúúú
t 3
t 2
t1
é
ë
êêêê
ù
û
úúúú
xy (t) = p0y p1y p2y p3yéë ùû
-1 3 -3 13 -6 3 0-3 3 0 01 0 0 0
é
ë
êêêê
ù
û
úúúú
t 3
t 2
t1
é
ë
êêêê
ù
û
úúúú
xz (t) = p0z p1z p2z p3zéë ùû
-1 3 -3 13 -6 3 0-3 3 0 01 0 0 0
é
ë
êêêê
ù
û
úúúú
t 3
t 2
t1
é
ë
êêêê
ù
û
úúúú
• 3parallelequations,inx,yandz:
70
• Bundleintoasinglematrix
• Efficientevaluation• PrecomputeC• Takeadvantageofexisting4x4matrixhardwaresupport
x(t) =p0x p1x p2x p3x
p0y p1y p2y p3y
p0z p1z p2z p3z
é
ë
êêê
ù
û
úúú
-1 3 -3 13 -6 3 0-3 3 0 01 0 0 0
é
ë
êêêê
ù
û
úúúú
t 3
t 2
t1
é
ë
êêêê
ù
û
úúúú
x(t) = GBezBBezTx(t) = C T
Matrix form
71
Drawing Bézier curves
• Generallynolow-levelsupportfordrawingsmoothcurves• I.e.,GPUdrawsonlystraightlinesegments
• Needtobreakcurvesintolinesegmentsorindividualpixels• Approximatingcurvesasseriesoflinesegmentscalledtessellation• Tessellationalgorithms• Uniformsampling• Adaptivesampling• Recursivesubdivision
72
• ApproximatecurvewithN-1 straightsegments• N choseninadvance• Evaluate
• Connectthepointswithlines• Toofewpoints?• Badapproximation• “Curve”isfaceted
• Toomanypoints?• Slowtodrawtoomanylinesegments• Segmentsmaydrawontopofeachother
x0
x2x3
Uniform sampling
!
xi = x ti( ) where ti =iN
for i = 0, 1,", N
xi =#a i
3
N 3 +#b i2
N 2 +#c iN+ d
x4
x1
x(t)
73
• Useonlyasmanylinesegmentsasyouneed• Fewersegmentswherecurveismostlyflat• Moresegmentswherecurvebends• Segmentsneversmallerthanapixel
• Variousschemesforsampling,checkingresults,decidingwhethertosamplemore
Adaptive Sampling
x(t)
74
Recursive Subdivision• Anycubic(ork-thorder)curvesegmentcanbeexpressedasacubic(ork-thorder)Béziercurve
“Anypieceofacubic(ork-thorder)curveisitselfacubic(ork-thorder)curve”
• Therefore,anyBéziercurvecanbesubdividedintosmallerBéziercurves
75
• deCasteljau constructionpointsarethecontrolpointsoftwoBéziersub-segments(p0,q0,r0,x) and(x,r1,q2,p3)
xp0
p1
p2
p3
de Casteljau subdivision
q0r0
r1
q2
76
Adaptive subdivision algorithm
1. UsedeCasteljauconstructiontosplitBéziersegmentinmiddle(t=0.5)
2. Foreachhalf• If“flatenough”:drawlinesegment• Else:recursefrom1.foreachhalf
• Curveisflatenoughifhullisflatenough• Testhowfarawaymidpointsarefromstraightsegmentconnectingstartandend• Ifaboutapixel,thenhullisflatenough
77
Today
Curves• Introduction• Polynomialcurves• Béziercurves• DrawingBéziercurves• Piecewisecurves
78
More control points
• CubicBéziercurvelimitedto4controlpoints• Cubiccurvecanonlyhaveoneinflection• Needmorecontrolpointsformorecomplexcurves
• k-1 orderBéziercurvewithk controlpoints
• Hardtocontrolandhardtoworkwith• Intermediatepointsdon’thaveobviouseffectonshape• Changinganycontrolpointchangesthewholecurve
• Wantlocalsupport• Eachcontrolpointonlyinfluencesnearbyportionofcurve
79
• Sequenceofsimple(low-order)curves,end-to-end• Piecewisepolynomialcurve,orsplines
http://en.wikipedia.org/wiki/Spline_(mathematics)
• Sequenceoflinesegments• Piecewiselinear curve(linearorfirst-orderspline)
• Sequenceofcubiccurvesegments• Piecewisecubic curve,herepiecewiseBézier(cubicspline)
Piecewise curves (splines)
80
Piecewise cubic Bézier curve
!
• Given 3N +1 points p0 ,p1,",p3N
• Define N Bézier segments:x0 (t) = B0 (t)p0 + B1(t)p1 + B2 (t)p2 + B3(t)p3
x1(t) = B0 (t)p3 + B1(t)p4 + B2 (t)p5 + B3(t)p6
#
xN -1(t) = B0 (t)p3N -3 + B1(t)p3N -2 + B2 (t)p3N -1 + B3(t)p3N
x0(t) x1(t)
x2(t)x3(t)
p0
p1p2
p3
p4p5
p6
p7 p8
p9
p10 p11
p12
81
• Globalparameteru,0<=u<=3N
Piecewise cubic Bézier curve
!
x(u) =
x0 ( 13 u), 0 £ u £ 3
x1( 13 u -1), 3 £ u £ 6
" "
xN -1( 13 u - (N -1)), 3N - 3 £ u £ 3N
ì
íïï
îïï
x(u) = xi 13 u - i( ), where i = 1
3 uêë úû
x0(t) x1(t)
x2(t)x3(t)
x(3.5)
x(8.75)
u=0u=12
82
Continuity
• Wantsmoothcurves• C0 continuity
• Nogaps• Segmentsmatchattheendpoints
• C1 continuity:firstderivativeiswelldefined• Nocorners• Tangents/normalsareC0 continuous(nojumps)
• C2 continuity:secondderivativeiswelldefined• Tangents/normalsareC1 continuous• Importantforhighqualityreflectionsonsurfaces
83
• C0 continuousbyconstruction• C1 continuousatsegmentendpointsp3i if p3i - p3i-1 = p3i+1 - p3i• C2 ishardertoget
Piecewise cubic Bézier curve
p0
p0
p1
p2
P3
P3
p2
p1
p4
p5
p6
p6
p5
p4
C1 continuousC0 continuous84
Piecewise cubic Bézier curves
• Usedoftenin2Ddrawingprograms• Inconveniences• Musthave4or7or10or13or…(1plusamultipleof3)controlpoints• Somepointsinterpolate(endpoints),othersapproximate(handles)• Needtoimposeconstraintsoncontrolpointstoobtain
C1 continuity• C2 continuitymoredifficult
• Solutions• Userinterfaceusing“Bézierhandles”• GeneralizationtoB-splines,nexttime
85
Bézier handles
• Segmentendpoints(interpolating)presentedascurvecontrolpoints• Midpoints(approximatingpoints)presentedas“handles”• CanhaveoptiontoenforceC1 continuity
[www.blender.org] Adobe Illustrator 86