The Essentials of CAGD -...

29
The Essentials of CAGD Chapter 3: Cubic B´ ezier Curves Gerald Farin & Dianne Hansford CRC Press, Taylor & Francis Group, An A K Peters Book www.farinhansford.com/books/essentials-cagd c 2000 Farin & Hansford The Essentials of CAGD 1 / 29

Transcript of The Essentials of CAGD -...

Page 1: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The Essentials of CAGD

Chapter 3: Cubic Bezier Curves

Gerald Farin & Dianne Hansford

CRC Press, Taylor & Francis Group, An A K Peters Bookwww.farinhansford.com/books/essentials-cagd

c©2000

Farin & Hansford The Essentials of CAGD 1 / 29

Page 2: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Outline

1 Introduction to Cubic Bezier Curves

2 Parametric Curves

3 Cubic Bezier Curves

4 Derivatives

5 The de Casteljau Algorithm

6 Subdivision

7 Exploring the Properties of Bezier Curves

8 The Matrix Form and Monomials

Farin & Hansford The Essentials of CAGD 2 / 29

Page 3: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Introduction to Cubic Bezier Curves

Cubic Bezier curves

– CAD/CAM– Graphic Design– Computer Graphics– Figure generated in PostScript

Basic principles of Bezier curveseasily explored via cubics

Farin & Hansford The Essentials of CAGD 3 / 29

Page 4: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Parametric Curves

Curve from calculus: function

y = 2x − 2x2

Graph of the function[

x

y

]

=

[

x

2x − 2x2

]

Parametric curve[

x

y

]

=

[

f (t)g(t)

]

f and g can be any kind of function

Domain is the real line

Try this:Parametric line thru 2 points

Farin & Hansford The Essentials of CAGD 4 / 29

Page 5: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Parametric Curves

Graph of a function

[

x

y

]

=

[

x

2x − 2x2

]

as a parametric curve:

x(t) =

[

x

y

]

=

[

t

2t − 2t2

]

Rotate 90 degrees

x(t) =

[

−2t + 2t2

t

]

Horizontal tangents do notcharacterize extreme points forparametric curves

Farin & Hansford The Essentials of CAGD 5 / 29

Page 6: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Parametric Curves

Parametric curves defined in 3D:

x(t) =

x

y

z

=

f (t)g(t)h(t)

Simple example: a helix

x(t) =

cos(t)sin(t)t

Farin & Hansford The Essentials of CAGD 6 / 29

Page 7: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Cubic Bezier Curves

Focus of this book: Bezier curves

– The most important type of polynomial curve

– Named after Pierre Bezier

– Defined for any polynomial degree

– First focus on cubic case n = 3

Farin & Hansford The Essentials of CAGD 7 / 29

Page 8: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Cubic Bezier Curves

x(t) =

[

−(1− t)3 + t3

3(1 − t)2t − 3(1− t)t2

]

Shape?

Rewrite as a combination of points

x(t) = (1− t)3[

−10

]

+ 3(1− t)2t

[

01

]

+ 3(1− t)t2[

0−1

]

+ t3[

10

]

Farin & Hansford The Essentials of CAGD 8 / 29

Page 9: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Cubic Bezier Curves

Cubic Bezier curve

x(t) = (1− t)3b0 + 3(1− t)2tb1 + 3(1 − t)t2b2 + t3b3

Bezier control points bi form the Bezier polygon

Cubic Bernstein polynomials B3i

x(t) = B30 (t)b0 + B3

1 (t)b1 + B32 (t)b2 + B3

3 (t)b3

More on the Bernstein polynomials in the next chapter

Farin & Hansford The Essentials of CAGD 9 / 29

Page 10: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Cubic Bezier Curves

Properties:

1 Endpoint interpolation2 Symmetry3 Invariance under affine maps4 Convex hull property5 Linear precision

Farin & Hansford The Essentials of CAGD 10 / 29

Page 11: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Cubic Bezier Curves

Convex hull property

t ∈ [−1, 2]

Extrapolation: t outside [0, 1]– No convex hull property– Unpredictable behavior

Farin & Hansford The Essentials of CAGD 11 / 29

Page 12: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Derivatives

Tangent vector

dx(t)

dt= −3(1− t)2b0

+ [3(1− t)2 − 6(1− t)t]b1

+ [6(1− t)t − 3t2]b2

+ 3t2b3

= 3[b1 − b0](1− t)2 + 6[b2 − b1](1− t)t + 3[b3 − b2]t2

= 3∆b0(1− t)2 + 6∆b1(1− t)t + 3∆b2t2

forward difference ∆bi

x(t) ≡ dx(t)/dt

Farin & Hansford The Essentials of CAGD 12 / 29

Page 13: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Derivatives

Example

x(t) = 3

[

11

]

(1− t)2

+ 6

[

0−2

]

(1− t)t

+ 3

[

11

]

t2

x(0.5) =

[

1.5−1.5

]

Farin & Hansford The Essentials of CAGD 13 / 29

Page 14: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Derivatives

x(t) = 3∆b0(1− t)2 + 6∆b1(1− t)t + 3∆b2t2

– Derivative of a cubic curve is a quadratic curve

– Evaluating “derivative curve” produces vectors

At the curve’s endpoints:

x(0) = 3∆b0 x(1) = 3∆b2

⇒ control polygon is tangent to the curve at the endpoints

Chapter 4: higher order derivatives

Farin & Hansford The Essentials of CAGD 14 / 29

Page 15: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The de Casteljau Algorithm

Recursive algorithm that constructs the point x(t) on a Bezier curve

Most important algorithm of all of CAGD

Many practical and theoretical ramifications

1959 Paul de Faget de Casteljau

Farin & Hansford The Essentials of CAGD 15 / 29

Page 16: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The de Casteljau AlgorithmGiven: b0, . . . ,b3 and t

Find: x(t)

b10 = (1− t)b0 + tb1

b11 = (1− t)b1 + tb2

b12 = (1− t)b2 + tb3

b20 = (1− t)b10 + tb11

b21 = (1− t)b11 + tb12

x(t) = b30 = (1− t)b20 + tb21

What operation is repeated?

Farin & Hansford The Essentials of CAGD 16 / 29

Page 17: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The de Casteljau Algorithm

Schematic toolb0b1 b10b2 b11 b20b3 b12 b21 b30

Implementation: 1D array data structure sufficient

Farin & Hansford The Essentials of CAGD 17 / 29

Page 18: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The de Casteljau Algorithm

Example

x(t) = (1− t)3[

−10

]

+ 3(1− t)2t

[

01

]

+ 3(1 − t)t2[

0−1

]

+ t3[

10

]

Evaluate at t = 0.5 using the triangular schematic tool

Make a sketch!

Farin & Hansford The Essentials of CAGD 18 / 29

Page 19: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The de Casteljau Algorithm

Just for fun: All intermediate points of many evaluations

Farin & Hansford The Essentials of CAGD 19 / 29

Page 20: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The de Casteljau Algorithm

Derivatives

b20b21 is tangent to the curve

x(t) = 3[b21 − b20]

Derivative as byproduct ofpoint evaluation

Great value computationally

Farin & Hansford The Essentials of CAGD 20 / 29

Page 21: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Subdivision

Curve over [0, t]

b0,b10,b

20,b

30

Curve over [t, 1]

b30,b21,b

12,b3

Find these control points:

b0

b1 b10

b2 b11 b2

0

b3 b12 b2

1 b30

Subdivide at t = 0.5Are the two curve arcs equal length?

Farin & Hansford The Essentials of CAGD 21 / 29

Page 22: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Subdivision

Repeated subdivision

Polygon converges to curve

Convergence is fast

Application?

Farin & Hansford The Essentials of CAGD 22 / 29

Page 23: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Subdivision

Application: curve / line intersection

True/False of minmax box / line intersection fast

How is convex hull property used?

Try outlining the intersection algorithmFarin & Hansford The Essentials of CAGD 23 / 29

Page 24: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Exploring the Properties of Bezier Curves

Self-intersection

Farin & Hansford The Essentials of CAGD 24 / 29

Page 25: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Exploring the Properties of Bezier Curves

Two inflection points

Cubic functions cannot have two inflection points⇒ Parametric curves more flexible

Farin & Hansford The Essentials of CAGD 25 / 29

Page 26: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

Exploring the Properties of Bezier Curves

Cusp: point where the first derivative vector vanishes

See for yourself!Run the de Casteljau algorithm for t = 0.5

Farin & Hansford The Essentials of CAGD 26 / 29

Page 27: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The Matrix Form and Monomials

Cubic Bezier curve:

b(t) = B30 (t)b0 + B3

1 (t)b1 + B32 (t)b2 + B3

3 (t)b3

Rewrite in matrix form:

b(t) =[

b0 b1 b2 b3]

B30 (t)

B31 (t)

B32 (t)

B33 (t)

=[

b0 b1 b2 b3]

1 −3 3 −10 3 −6 30 0 3 −30 0 0 1

1t

t2

t3

Farin & Hansford The Essentials of CAGD 27 / 29

Page 28: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The Matrix Form and Monomials

Monomial polynomials: 1, t, t2, t3

Reformulate a Bezier curve

b(t) = b0

+ 3t(b1 − b0)

+ 3t2(b2 − 2b1 + b0)

+ t3(b3 − 3b2 + 3b1 − b0)

= a0 + a1t + a2t2 + a3t

3

What is the geometric interpretation

of the ai?

Farin & Hansford The Essentials of CAGD 28 / 29

Page 29: The Essentials of CAGD - FarinHansford.comfarinhansford.com/books/essentials-cagd/slides/chap3.pdf · Farin&Hansford The Essentials of CAGD 2/29. ... – CAD/CAM – Graphic Design

The Matrix Form and Monomials

The monomial coefficients ai are defined as

[

a0 a1 a2 a3]

=[

b0 b1 b2 b3]

1 −3 3 −10 3 −6 30 0 3 −30 0 0 1

Inverse process:

[

b0 b1 b2 b3]

=[

a0 a1 a2 a3]

1 −3 3 −10 3 −6 30 0 3 −30 0 0 1

−1

Square matrix above is nonsingular⇒ Any cubic curve can be written in Bezier or monomial form

How do we know that the matrix is nonsingular?

Farin & Hansford The Essentials of CAGD 29 / 29