Lecture 20: Bezier Curves & Splines - CS CSU Homepagecs410/yr2016fa/more_progress/cs410_F... ·...

Post on 15-Apr-2018

215 views 2 download

Transcript of Lecture 20: Bezier Curves & Splines - CS CSU Homepagecs410/yr2016fa/more_progress/cs410_F... ·...

Lecture 20:Bezier Curves & Splines

December 6, 2016

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 1

Review: The Pen Metaphore• Think of putting a pen to paper• Pen position described by time t

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 2

Seeingtheactionofdrawingisthekey,sothisstaticdrawingonlypartlycapturesthepointofthisslide.

Review: Third Order Curves• Third-order functions are the standard:

• Why 3?– Lower-order curves cannot be smoothly joined.– Higher-order curves introduce “wiggles”.

• Without loss of generality: 0 <= t <= 1.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 3

x t( ) = axt3 + bxt2 + cxt + dxy t( ) = ayt3 + byt2 + cyt + dyz t( ) = azt3 + bzt2 + czt + dz

Review:CubicExamples

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 4

Review:Notation

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 5

T = t3, t2, t,1!" #$C =

ax ay azbx by bzcx cy czdx dy dz

!

"

######

$

%

&&&&&&

Q t( ) = T ⋅C

Alternatively: Q t( )T =CT ⋅TT

Review:TangentstoCubicCurves

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 6

ThederivativeofQ(t)isitstangent:

ddt Q(t) = [ x(t), y(t), z(t)]d

dtddt

ddt

ddt Q(t)x = 3axt2 + 2bxt + cx

ddt Q(t) = [3t2, 2t, 1, 0] C

Againthetimemetaphorisuseful,thetangentindicatesinstantaneousdirectionandspeed.

Review:TheHermite Matrix

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 7

OK,thatwasthexdimension.Howabouttheothers?

Theyare,ofcourse,thesame:

ax ay azbx by bzcx cy czdx dy dz

=

2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0

P 0( )P 1( )dP 0( )dt

dP 1( )dtM

FromHermitetoBezier

What’s wrong with Hermite curves? Nothing,unless you are using a point-and-click interface

Bezier curves are like Hermite curves, exceptthat the user specifies four points (p1, p2, p3, p4).The curve goes through p1 & p4.Points p2 & p3 specify the tangents at the endpoints.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 8

MorePrecisely....

R1 = P1 = 3(P2 - P1)ddt R4 = P4 = 3(P4 - P3)

ddt

Tangentsatstartandendarenowdefinedbyintermediatepoints.

Q:Why‘3’?WhynotR1=(P2-P1)?

A:Thinkof4evenlyspacedpointsinaline

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 9

Hermite® Bezier

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 10

The Hermite geometry matrix is relatedto the Bezier geometry matrix by:

= MHBGB

GH =

P1P4R1R4

=

1 0 0 00 0 0 1-3 3 0 00 0 -3 3

P1P2P3P4

Hermite® BezierFor Hermite curves, Q(t) = T MHGH,where GH = [P1, P4, R1, R4]T, T = [t3, t2, t, 1]

and MH =

2 -2 1 1-3 3 -2 -10 0 1 01 0 0 0

So, Q(t) =T MHMHBGB

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 11

TheBezierBasisMatrixQ(t) =T(MHMHB)GB

MB = MHMHB =

-1 3 -3 13 -6 3 0-3 3 0 01 0 0 0

Q(t) = TMBGB

Seepage364toconnectwithdescriptioninourtextbook.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 12

TheBezierBlendingFunctions

Q(t) = P1(-t3 + 3t2 -3t + 1)+ P2(3t3 - 6t2 + 3t)+ P3(-3t3 + 3t2)+ P4(t3)

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 13

Addthemup.

( -t3 + 3t2 - 3t + 1)+ ( 3t3 - 6t2 + 3t)+ (-3t3 + 3t2)+ ( t3)

0t3+0t2+0t+1

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 14

StaywithintheConvexHull

If you graph the four Bezier blending functionsfor t=0 to t=1, you find that they are alwayspositive and always sum to one.

Therefore, the Bezier curve stays within theconvex hull defined by P1, P2, P3 & P4.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 15

Examples1.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 16

Examples2.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 17

Example3D

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 18

Bezier Curves are Common• You have probably already used them.• For example, in PowerPoint

– Build a shape– Then select edit points– Notice the control ‘wings’

• Enhancements– Ways to introduce constraints

• Smooth Point• Straight Point• Corner Point

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 19

SteppingBack

What should you be learning? Should you memorizeMH and MB? No! That’s what reference books are for.

You should know what GH and GB are. You shouldknow how to derive MH from the parametric form ofthe cubic equations. You should know how to deriveMB from MH. If you understand these concepts, youcan look up or rederive the matrices as necessary.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 20

deCasteljauCurves

There is another way to motivate curves.

Lets say that I have four control points

P2

P4

P3

P1

Now for something completely different.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 21

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 22

To find the midpoint of the curve correspondingto those control points:

Connect the point between P1 and P2 where t = 0.5with the point between P3 & P2 where t = 0.5; Do the same with the P2-P3 & P3-P4 lines

P2

t=0.5 t=0.5

t=0.5

P4

P3

P1

Now, connect these two lines at their t = 0.5 points

P2

t=0.5 t=0.5

The t = 0.5 point on the resulting segment isthe midpoint (t = 0.5 point) of some type of curve which is made up of weighted averages of the control points (we’ll soon see what kind of curve)

t=0.5

t=0.5

P4

P3

P1

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 23

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 24

We can extend this idea to any t value.

To compute the t = 0.25 point, connect the 0.25 points of the original lines...

P2

t=0.25

t=0.25

t=0.25

P4

P3

P1

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 25

Now, connect these lines at their t = 0.25 locations,and find the point where t = 0.25 of the resulting line

In this way, you can compute the 3rd-order curvefor any value of t

P2

t=0.25

t=0.25

t=0.25

P4

P3

P1

AlgebraicDefinition• The equations of the three original lines are:

= ( )A1 t + ( ) − 1 t P1 t P2 = ( )A2 t + ( ) − 1 t P2 t P3 = ( )A3 t + ( ) − 1 t P3 t P4

= ( )B1 t + ( ) − 1 t A1 t A2 = ( )B2 t + ( ) − 1 t A2 t A3

= ( )C1 t + ( ) − 1 t B1 t B2

• The equations of the next two joining lines are:

• Finally, the line between the two joining lines is:

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 26

BeginSubstitutions• Substitute equations for A1 and A2 into B1

= ( )B1 t - + ( ) - t 1 2 P1 2 t ( ) - t 1 P2 t2 P3

+ + ( ) + - t2 1 2 t P1 ( )- + 2 t2 2 t P2 t2 P3

- + + - + P1 2 t P1 t2 P1 2 t P2 2 t2 P2 t2 P3

= ( )B1 t + ( ) - 1 t ( ) + ( ) - 1 t P1 t P2 t ( ) + ( ) - 1 t P2 t P3

=

=

Factoring the result

• Likewise, substitute A2 and A3 into B2

= ( )B2 t − + ( ) − t 1 2 P2 2 t ( ) − t 1 P3 t2 P4

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 27

ResultingThirdOrderCurveSubstitute equations for B1 and B2 into C1

( )C1 t = ( ) - 1 t ( ) - + ( ) - t 1 2 P1 2 t ( ) - t 1 P2 t2 P3

+ t ( ) - + ( ) - t 1 2 P2 2 t ( ) - t 1 P3 t2 P4

( )- - + + 3 t t3 3 t2 1 P13 2 + ( ) - + 3 t 6 t 3 t P2

+ + ( )- + 3 t3 3 t2 P3 t3 P4

=

And After Factoring

= ( )C1 t + - + ( ) - 1 t 3 P1 3 t ( ) - t 1 2 P2 3 t2 ( ) - t 1 P3 t3 P4

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 28

Bezier=deCasteljau

But those last four functions are exactly the Bezier blending functions!

The recursive line intersection algorithmcan therefore be used to gain intuition about

the behavior of Bezier functions

Not something completely different afterall.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 29

TheRoadLessTraveled(forgoodreason)

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 30

In principle, we can use de Casteljau’s algorithm tofit a continuous curve through an arbitrary numberof points

One problem: if any point moves, then every pointon the curve moves. There is no “locality”.

P1

P2P3

P4

P8

P7

P6P5

P11

P10P9

segment #1

segment #2

segment #3

Points P1 through P4 define the first segment, P2 through P5 the second, and PN through PN+3 the Nth segment.

P1

P2P3

P4

P8

P7

P6P5

P11

P10P9

LocalityofControlisGood!

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 31

Note that these 3rd-order segments are neither exactly Hermite nor Bezier curves:

1) The curve from Pi to Pi+3 is only drawn betweenPi+1 and Pi+2 (otherwise segments would overlap)

2) The curve is not constrained to pass through eitherPi+1 or Pi+2.

Therefore, what is their equation?

SomeNewRequirements

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 32

B-Splines

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 33

By convention, the geometry matrix andbasis matrix for B-Splines are:

úúúú

û

ù

êêêê

ë

é

=

+

+

+

3

2

1

i

i

i

i

B

PPPP

Gúúúú

û

ù

êêêê

ë

é

--

--

=

0141030303631331

61

BsM

B-SplineBlendingFunctions

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 34

Blend = T MBs

[ ]úúúú

û

ù

êêêê

ë

é

--

--

×=

0141030303631331

61123 tttBlend

Bo = 16 −t3 +3t2 −3t +1( )Pi = −16 t −1( )3 Pi

( ) 123

1 46361

++-= iPttB ( ) 223

2 133361

++++-= iPtttB

( ) 33

3 61

+= iPtB

PlotofBlendingFunctions

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 35

SeeCycleinBlendingFunctions

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 36

As the Spline Sequences from one segment to the next, control points are passed from B4, to B3, to B2 and finally to B1. Consequently, the weight exerted on the curve rises then falls as indicated by the curve above.

B4

B3 B2

B1

ExampleofB-Spline

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 37

= ( )Qj t Gj ( )B t

= G4

é

ë

êêê

ù

û

úúú

8 5 4 16 9 7 50 0 0 0

= G3

é

ë

êêê

ù

û

úúú

6 8 5 45 6 9 70 0 0 0

= G2

é

ë

êêê

ù

û

úúú

5 6 8 52 5 6 90 0 0 0

= G1

é

ë

êêê

ù

û

úúú

2 5 6 81 2 5 60 0 0 0

MoreVariations

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 38

We have just described uniform, non-rational B-Splines

Uniform means that the control points are evenly spaced(in terms of the parameter t).

It is also possible to have non-uniform B-Splines. Why?because it is easier to interpolate starting and endingpoints, and it is possible to reduce the continuity atspecific join points.

Non-uniform B-Splines• Every control point must have a

corresponding t-value– This is called a “knot vector”

• If the spacing (in t) between two control points is small, then a sharp curve will result.

• If the spacing (in t) is zero, the curve becomes discontinuous.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 39

The Standard Knot Vector• The “standard knot vector” begins and ends

with a four-fold knot:– e.g., for 5 control points T = (0, 0, 0, 0, 1, 2, 3, 4,

5, 5, 5, 5,)

• This means that the B-Spline will not loose the last point(s), and will behave correctly near the endpoints.

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 40

RationalBSplines

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 41

• So far we have represented curves as curves with one free parameter (t) and three dependent parameters (x, y, x):X(t) = axt3 + bxt2 + cxt + dY(t) = ayt3 + byt2 + cyt + dZ(t) = azt3 + bzt2 + czt + d

• What else could we do?

Homogenous Coordinates!• Why not use four dependent functions?

X(t) = axt3 + bxt2 + cxt + dY(t) = ayt3 + byt2 + cyt + dZ(t) = azt3 + bzt2 + czt + dW(t) = awt3 + bwt2 + cwt + d

• The image position at t is X(t)/W(t), Y(t)/W(t) and Z(t)/W(t)

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 42

What does this gain us?• Why are (non-rational) curves too expensive?

– For every value of t, we compute x, y, z– Then we project x, y, z (given viewpoint)– How small should the increment in t be?

• Depends on the projection• Very small to avoid gaps in the projection• But this makes curves very expensive…

• Rational form fixes this problem (next slide)

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 43

Closing Argument - NURBS• A remarkable property (trust me):

– The curve made by computing a rational BSpline for all t and then projecting it is…

– … the same curve made by projecting the control points, and then computing the 2D BSpline between the control points

• So Non-Uniform Rational B-Splines are drawn by projecting the control points, and then recursively computing the (minimal set of) intermediate points in 2D

12/6/16 CSU CS410 © Bruce Draper & J. Ross Beveridge 44