Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9....

13
9. Parametric curves CS527 Computer Graphics 1 Note 9: Parametric representation of curves ( Reading: Text: Chapter 10, Foley et al. Section 9.2 ) - representing an object by a parametric description of its surface. patch-based (or piecewise) surface closed smooth surface smooth surface provides flexibility in shape design The Utah teapot A parametric 3D curves is defined by 3 univariate functions: Q ( u ) = ( Q x (u), Q y (u), Q z (u) ); u i ? u ? u f A parametric surface may be visualized as made up of a family of curves. A parametric 3D surface is defined by 3 bivariate functions: Q ( u,v ) = ( Q x (u,v), Q y (u,v), Q z (u,v) ) where 0 ? u ? 1 and 0 ? v ? 1 As u is varied from 0 to 1 for a constant v , the functions again sweep out a 3D curve. A family of such curves are generated as v is varied from 0 to 1, thus defines a 3D surface Modeling of long smooth cubic curve A long curve is formed by joining pieces of curve segments. !Each curve segment interpolates its end control points. !The smoothness over the whole piece-wise curve is ensured by maintaining smooth continuities at all joints continuity at joints is maintained by manipulating the end-points, tangent vectors & possibly curvatures at the joints. Parametric Polynominal curves = = n k k k u C n P 0 ) ( (n+1) degrees of freedom.

Transcript of Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9....

Page 1: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

1

Note 9: Parametric representation of curves ( Reading: Text: Chapter 10, Foley et al. Section 9.2 ) - representing an object by a parametric description of its surface.

•patch-based (or piecewise) surface •closed smooth surface •smooth surface provides flexibility in shape design

The Utah teapot A parametric 3D curves is defined by 3 univariate functions:

Q ( u ) = ( Qx(u), Qy(u), Qz(u) ); ui ? u ? uf A parametric surface may be visualized as made up of a family of curves. A parametric 3D surface is defined by 3 bivariate functions:

Q ( u,v ) = ( Qx(u,v), Qy(u,v), Qz(u,v) ) where 0 ? u ? 1 and 0 ? v ? 1

•As u is varied from 0 to 1 for a constant v , the functions again sweep out a 3D curve.

•A family of such curves are generated as v is varied from 0 to 1, thus defines a 3D surface

Modeling of long smooth cubic curve •A long curve is formed by joining pieces of curve segments.

!Each curve segment interpolates its end control points. !The smoothness over the whole piece-wise curve is ensured by maintaining smooth

continuities at all joints •continuity at joints is maintained by manipulating the end-points, tangent vectors &

possibly curvatures at the joints. Parametric Polynominal curves

∑=

=n

k

kk uCnP

0

)(

(n+1) degrees of freedom.

Page 2: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

2

Start with parametric cubic curve segments. Design criteria: 1. local control; 2. smoothness; 3. stability; 4. easy of rendering. Why choose piece-wise Parametric Cubic curves ? •For a parametric curve, all derivatives exist and can be computed analytically. •Parametric cubic is the lowest order parametric curve that can meet all continuity

requirements. •Higher order curves are more wiggly , may introduce unwanted oscillations into the

curve. •A single cubic curve segment cannot model enough details into the curve. •A cubic curve is smooth within its segment. Smoothness for the whole curve can be

achieved by matching tangent vectors at the joints of segments.

=

3210

111132

32

321

31

31

311

0001

3210

32

32

CCCC

PPPP

So, what exactly is continuities at a joint ? Geometric & parametric continuities, G n & C n

Given a curve with its defining polynomials: Q(u) = ( Qx (u), Qy (u), Qz (u) ), Q(u)' = dQ(u) / du = parametric tangent vector, TV = velocity wrt u . Q(u)'' = d2Q(u) / du2 corresponds to acceleration A curve with C n possesses all (n-1), ?.. 0 continuities. 0th derivative continuity Q 1( uf ) = Q 2( ui ): G 0, C 0 or joint continuity

1st derivative continuity Q 1'( uf ) = Q 2'( ui ): C 1 or velocity continuity

For TV1 = k* TV2, k > 0: If k=1, then C 1. If k <> 0, then G 1

C 1 : TVs of the 2 segments are equal in direction & magnitude at the joint. G 1 : TV1 and TV2 are proportional, only their directions are equal at the joint. Example: Q1 and Q2 are both G1 and C 1 at P2, but Q1 and Q3 are only G 1 at P2.

P0

P1 P2

P3

0 " u

Page 3: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

3

2nd derivative continuity Q 1''( uf ) = Q 2''( ui ): C 2 or acceleration continuity G 2 can be similarly defined Example: S joined to C0 , C1, C2 with C 0, C 1, C 2. Difference is slight at joint but obvious away from joint.

Ways of modeling CUBIC parametric curves

For a parametric cubic curve, ∑=

=3

0

)(i

iiucuQ , (9-1)

the shape of Q(u) is determined by the coefficients ci of the polynomial. Need a more intuitive way of controlling the curve segment! #Hermite curve:

rearrange the function form so that shape of each curve segment may be controlled by its

• 2 end points • 2 end tangent vectors (TVs).

# Alternatively use only control points to model the interpolating curve segment. Bezier curve: uses

• 2 end pts • 2 other control pts to control TVs at end-points.

#### B-spline , ?.. Hermite curves: Given geometric constraints: 2 endpts & 2 TVs, Find: a smooth cubic curve, Q(u) that interpolates the end-points and TVs at end-points:

Q (0) = p0 , Q ' (0) = R0 , Q (1) = p3 , Q ' (1) = R3 . (9-2)

Page 4: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

4

From eqn (9-1): Q (u) = c0

+ c1u + c2u2 + c3u3

, 0 <= u <= 1 (9-3)

With U = [1 u u2 u3], write eqn (9-3) in matrix form: Q (u) = [1 u u2 u3] [ c0 c1 c2 c3 ] T

or Q (u) = U c (9-4) ∴∴∴∴ Q ' (u) = [ 0 1 2u 3u 2 ] c so c = [ c0 c1 c2 c3 ] = ? Using condition (9-2) to find c,

Q (0) = p0 = [ 1 0 0 0 ] c Q (1) = p3 = [ 1 1 1 1 ] c Q ' (0) = R0 = [ 0 1 0 0 ] c Q ' (1) = R3 = [ 0 1 2 3 ] c

Write this simultaneous algebric equations in matrix form:

Denote the data matrix as Hermite geometric vector qH and write eqn (9-5a) as qH = M c ( 9-5b ) Define Hermite basis matrix as the inverse of M, i.e. MH = M-1 or MH M = I Thus, ∴∴∴∴ c = MH qH

Q(u

p0

R3 R0

p3

) 5a-9 (

cccc

3210001011110001

3

2

1

0

3

0

30

=RRpp

=

112-21-2-33-

01000001

M H

Page 5: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

5

From eqn (9-4), Q (u) = U c = U MH qH ( 9-6a )

The TVs and curvatures at any point along the curve can be obtained from its derivatives: Q' (u) = U' MH qH , U' = [ 0 1 2u 3u2 ] Q" (u) = U" MH qH , U" = [ 0 0 2 6u ] Express: Q(u) = U MH qH = bH qH where

bH = U MH ( Hermite Blending function )

= [ (2u3 - 3u2 + 1) (-2u3 + 3u2) (u3 - 2u2 + u) (u3 - u2) ]

= [ b0(u) b1(u) b2(u) b3(u) ]

Hermite Blending function b0(u) b1(u) b2(u) b3(u): are called Hermite cubic basis or blending function. •The Hermite cubic curve is therefore a weighted sum of the elements of qH , i.e.

•b1 (u) = 1 - b0 (u) •b0, b1 >> b2, b3 . ⇒ endpoints more influence than TVs.

=

112-21-2-33-01000001

uuu1 32

∑=

≤≤=∴ 3

0 i Hii ) 6b-9 ( 1 u 0 (u) b (u) qQ

u

P2(1)

b3

b2

b1

1.0

1.0 1.0

0

∑=

≤≤= 3

0 i Hii 1 u 0 (u) b (u) qQ

Page 6: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

6

Convex hull property Convex set: A convex set is a collection of points in which the line connecting any pair of points in the set lies entirely within the set. Convex Hull: Given a collection of points, the convex hull is the smallest convex set that contains the points. Convex hull property Condition for a parametric curve to satisfy convex hull property:

i all for] 1 0, [ u ,0 (u)bi ∈≥

When a curve satisfies convex hull properties, then: • any point on the curve is a weighted average of its control points. • the curve lies in the convex hull of the control polygon (a similar condition exists for

surfaces).

Recall: Hermite curve : Q (u) = bH qH = U MH qH Features of its geometrical controls: • 2 endpts & 2 TVs at endpts. • shape control not intuitive, no convex hull property - not desirable for interactive

design. Bezier curve: • geometrical controls: 2 end pts + 2 other control pts to control endpt TVs. • curve satisfies convex hull property. Consider modeling the curve segment Q(u) using 4 control points p0, p1, p2, p3, also with 0 <= u <= 1. The curve must satisfy the following conditions:

Q(0) = p0 ; Q(1) = p3 Q'(0) = 3(p1 - p0 ) ; Q'(1) = 3(p3 - p2).

With U = [1 u u2 u3], and Q (u) = [ 1 u u2 u3 ] [ c0 c1 c2 c3 ] T ? Uc, and Q ' (u) = [ 0 1 2u 3u 2 ] c, use condition (9-7) to find c ,

Q (0) = p0 = [ 1 0 0 0 ] c Q (1) = p3 = [ 1 1 1 1 ] c Q' (0) = 3( p1 - p0 ) = c1

p1 = [ 1 1/3 0 0 ] c

( 9-7 )

∑=

=k

0 i i 1 (u) b

Page 7: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

7

Q' (1) = 3( p3 - p2 ) = c1 + 2c2 + 3c3 p2 = [ 1 2/3 1/3 0 ] c

In matrix form:

or p = M c MB = M -1 and MB M = I Thus, And, c = MB p

Q (u) = U c = U MB p

Q (u) = U MB p = bB p ( 9-8 ) bB = [ ( 1 - u )3 3u ( 1 - u )2 3u 2 ( 1 - u ) u3 ]

= [ bB0(u) bB1(u) bB2(u) bB3(u) ] ( 9-9 ) Another formulation of Bezier curve: Bezier curve of degree n can be defined as

where p i are the control points, B i,n ( u ) are Bezier blending function (or Bernstein polynomial) where nCi is the binomial coefficient, nCi = n! / i! ( n - i )! The curve segment so generated satisfies the convex hull properties. For cubic curve, n = 3.

B i,n ( u ) = nCi u i (1- u) n- i ( 9-11 )

=

3

2

1

0

cccc

111101/32/31001/310001

3

2

1

0

pppp

1

− ==

13-31-036-30033-0001

M MB

=

3

2

1

0

pppp

and p

=

3

2

1

0

13-31-036-30033-0001

uuu1 3

pppp

2

∑=

≤≤= n

0 i ni,i ) 10-9 ( 1 u 0 ,(u) B (u) pQ

Page 8: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

8

B0,3 ( u ) = 1 . u0 ( 1 - u ) 3 = ( 1 - u ) 3 B1,3 ( u ) = 3u ( 1 - u ) 2

B2,3 ( u ) = 3( 1 - u ) u2

B3,3 ( u ) = u3 ( 9-12 ) Note that eqns (9-10) & (9-8) and eqns (9-12) & (9-9) are exactly identical, i.e. Bi,3 ( u ) = bBi(u). Explicit form of eqn (9-8)or (9-10) : Q (u) = ( 1 - u )3 p0 + 3u ( 1 - u )2 p1 + 3u 2 ( 1 - u ) p2 + u3 p3 Plotting the Bezier blending functions bBi Each bBi ( u ) != 0, <= 1 over the entire u-domain, ⇒⇒⇒⇒only global control of shape for the whole

curve when any one control point is moved. NOT local control. Note:

nCi = 3Ci = 3! / i! ( 3 - i )!

1. 1.

bB2(u)

bB3(u)

bB1(u)

bB0(u)

0 1.

u0.

Object space

u

Domain space

i all for

1 (u) b 3

0 i iB

∑=

=

Page 9: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

9

Join Bezier curve segments Q(1) (u) & Q(2)

(u) to have C 0 , C 1 , C 2 continuities •C 0 continuity: p0

(2) = p3(1) (9 -13)

•C 1 continuity: p1

(2) - p0(2) = p3

(1) - p2(1)

p1(2) = 2 p3

(1) - p2(1) (9 -14)

or p3(1) = ½ ( p1

(2) + p2(1) )

•C 2 continuity: Q(1)

" (1) = Q(2)" (0)

$ p0(2) - 2p1

(2) + p2(2) = p3

(1) - 2p2(1) + p1

(1) or p2

(2) = p1(1) - 4(p2

(1) + p3(1)) (9 -15)

Thus to have C 2 continuity, Q(2)

(u) has only p3(2) as free control point.

The locations of p0

(2), p1(2) , p2

(2) are restricted by eqns (9-9, 9-10, 9-11). de Casteljau representation of Bezier curves (recursive subdivision): de Casteljau algorithm generates points on the curve by repeated linear interpolation. Let p0 , p1, � , pn be the control points of a Bezier curve of degree n defined in 0 <= u <= 1. Define: pi

r (u) = ( 1- u ) pir-1 (u) + u pi+1

r-1 (u) ( 9-16 ) where for each r = 1, �, n, i = 0,�, n � r, pi

0 (t) = pi

Then a point on the curve with parameter value u is given by p0

n (u), i.e. Q (u) = p 0n (u). Unraveling the recursive formula eqn (9-16) by substituting for all levels of recursions will take us back to the Berstein representation for the Bezier curve given by eqns (9-10) or (9-8). e.g. with ( n = 3 ), r = 1,2,3, then Q (u) = p0

3 (u). r = 1, i = 0,.., (3-1). p0

1 (u) = ( 1- u ) p0 + u p1 = L1

p11 (u) = ( 1- u ) p1

+ u p2 = H p2

1 (u) = ( 1- u ) p2 + u p3 = R2

r = 2, i = 0, (3-2). p0

2 (u) = ( 1-u ) p01 (u) + u p1

1 (u) = L2 p1

2 (u) = ( 1-u ) p11 (u) + u p2

1 (u) = R1

Q(1) (u)

Q(1) (u) p3

(2)

p1(1)

p0(1)

P2(1)

P0(2 ) = P3

( 1)

P1(2)

P2(2)

Page 10: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

10

r = 3, i = (3-3). p0

3 (u) = ( 1- u ) p02 (u) + u p1

2 (u) = L3 Substitute p0

2 (u) and p12 (u) from above expressions, will get back eqn ( 9-10 ),

i.e. Q (u) = p03 (u).

Graphically draw L1H, HR2, L2R2 such that: P0L1/ L1P1 = P1H/ HP2 = P2R2/ R2P3 = L1L2/ L2H = HR1/R1R2

= L2L3/ R0R1 = u / (1-u ) then, with u=0.615: L3 = R0 = p0

3 ( 0.615) = Q (u= 0.615). Splitting Bezier curve Let p be the geometric vector denoting the original set of control points for a Bezier curve. We can use de Casteljau recursive subdivision method to divide p into its left and right sub-curve at any value of u.

L0 = p0 L1 = ( 1- u ) p0

+ u p1 L2 = ( 1-u ) p0

1 (u) + u p11 (u)

= ( 1- u )2 p0 + 2u ( 1-u ) p1 + u 2 p2

L3 = ( 1- u ) p02 (u) + u p1

2 (u) = ( 1- u )3p0

+3u ( 1-u )2p1+3u2( 1-u ) p2+ u3p3 So, Similarly:

Suppose set u=1/2 to generate the left half curve and right half curve.

p2

u

L1

R2

p1

L2

p0 = L0

L3 = R0

H

R1

−−−−−

−=

3

2

1

0

3

2

1

0

uuuuuuuuuu

uu

pppp

LLLL

3223

22

)1(3)1(3)1(0)1(2)1(00)1(0001

) 18a-9 (

uuuuuuuuuu

uu (u)

)1(3)1(3)1(0)1(2)1(00)1(0001

3223

22

−−−−−

−=L

BD

) 18b-9 (

1000uu)(100uu)2u(1u)(10uu)(13uu)3u(1u)(1

(u)22

3223

−−−−−−

=RBD

Page 11: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

11

pL (u=1/2) = [ L0, L1, L2, L3 ] T pR (u=1/2) = [ R0, R1, R2, R3 ] T

As the subdivisions continue indefinitely, the set {R0} eventually forms the exact curve. Conversion between curve representations Given: a curve represented by geometry vector g1 and basis matrix M1, Find: the equivalent geometric vector g2 and basis matrix M2 in another representation, an identical curve can be generated using M2 and g2.

T M2 g2 = T M1 g1 M2 g2 = M1 g1

Solve for g2 : M2

-1 M2 g2 = M2

-1 M1 g1

g2 = M2-1

M1 g1 = M1,2 g1 The matrix that converts a known geometry vector for repn.1 into the geometry vector for repn.2 is: M1,2 = M2

-1 M1 . ( 9-19 ) Rendering curves: Q(u) = U M q = b q , 0 <= u <= 1 with bH = [ (2u3 - 3u2 + 1) (-2u3 + 3u2) (u3 - 2u2 + u) (u3 - u2) ] bB = [ ( 1 - u )3 3u ( 1 - u )2 3u 2 ( 1 - u ) u3 ] i.e. we will be plotting a function of the form: f (u) = c0

+ c1u + c2u2 + c3u3

( 9-20 ) I. Iterative evaluation method (1) simple brute-force iterative method

The polynomials are evaluated at successive value of u using Horner's method to factor the polynomials:

f (u) = c0 + c1u + c2u2

+ c3u3 ,

= c0 + u (c1 + u ( c2 + u (c3))

For each 3D point display, the cost is: 3 x ( 3 multi + 3 add )

If the points { ui } are uniformly spaced, we can use the method of forward differences to evaluate Q(uk ) using only O(n) additions and no multiplications. (2) Forward differencing Let the function f(u) be a component of Q(u). Forward difference of f(u) in steps of δ :

∆f(u) = f(u+δ) � f(u), δ > 0 ( 9-21 ) Thus

f(u+δ) = f(u) + ∆f(u) or in iterative form:

Page 12: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

fk+1 = fk + ∆fk with uk+1 - uk = δ = constant For a polynomial of degree 3: f (u) = c0

+ c1u + c2u2 + c3u3

( 9-20 ) ∆f(u) = 3c3 u2δ + u(3c3 δ 2 + 2c2δ) +c3 δ 3 + c2 δ 2 + c1 δ ( 9-22 ) ∆ 2f(u) = ∆(∆f(u)) = ∆ f(u+δ) � ∆ f(u). ( 9-23 ) ∴ ∆ 2f(u) = 6c3 δ 2u + 6c3 δ 3 + 2c2 δ 2 ( 9-24 ) similarly, ∆ 3fk = ∆ 2 fk+1 - ∆ 2 fk or ∆ 3f(u) = ∆(∆2f(u)) = 6c3 δ 3 ( 9-25 ) i.e. the 3rd forward difference for a cubic function (degree 3) is a constant for all k. The forward difference is recursive and, in general: ∆ m+1 fk = ∆ m fk+1 + ∆ m fk ∴∴∴∴ ∆ 2 fk -1 = ∆ 2 fk-2 + ∆ 3 fk-2 ,

∆ fk = ∆ fk -1 + ∆ 2 fk-1 , ( 9-26 ) fk+1 = fk + ∆fk To use these results in an algorithm that iterates for

u = kδ = 0 .. 1, or k = 0 .. 1/δ compute initial conditions ( u = 0 ) from eqns (9-20,2 ∆ 0f0 ≡ f0 = c0 , ∆ 1f0 = c3 δ 3 + c2 δ 2 + c1δ , ∆ 2f0 = 6c3 δ 3 + 2c2 δ 2, ∆ 3f0 = 6c3δ 3 = ∆ 3fn . Subsequent f values can be computed from eqn ( 9-2 The evaluation of Q(u) therefore needs only 9 additioto only uniform steps in u, and is prone to accumulat Forward differencing uses fixed subdivision in rende Recursive evaluation method for Bezier curve: •recurvsive subdivision avoids unnecessary computa

flatness. •de Casteljau algorithm subdivide a Bezier curve any

smaller curves, each with their respective distinct•repeating subdivision produces closer approx. to the

based on a linearity test applied to the convex hu

∆ 3fk = 6c3 δ 3

12

2,24,25):

6 ).

ns for each 3D point. But it applies ion of numerical errors.

ring the curve.

tion, but takes time to test for

where along its length into two control polygons. curve. Termination criterion can be

ll, simple for a Bezier curve. How?

Page 13: Parametric representation of curves - Computer Scienceyang/teach/cs5270/oldnotes/note09.pdf · 9. Parametric curves CS527 Computer Graphics 6 Convex hull property Convex set: A convex

9. Parametric curves CS527 Computer Graphics

13

Bezier curves in OpenGL OpenGL supports Bezier curves through mechanisms called evaluators that are used to compute the blending functions of any degree. Evaluators do not require uniform spacing of u. Bezier curves can then be rendered at any precision.

/* define and enable a 1-dimemsional evaluator for Bezier curve */ point ctrlpts[ ] = { ??. } ; glMaplf ( GL_MAP1_VERTEX_3, 0.0 1.0, 3, 4, ctrlpts); glEnable (GL_MAP1_VERTEX_3);

/* range of U = [ 0.0, 1.0], 3 components for each crtlpt, k=4 */ ??.

/* With evaluator enabled, draw the Bezier curve */ glBegin (GL_LINE_STRIP); for ( i = 0; i <= 30; i ++) glEvalCoord1f ( (Glfloat) i/30.0); glEnd ( );