4: Parametric and surfaces

Lecture 1: Euclidean, similarity, affine and projective transformations. Homo- geneous coordinates and matrices. Coordinate frames. Perspective projection and its matrix representation.

Lecture 2: Vanishing points. Horizons. Applications of projective transforma- tions.

Lecture 3: Convexity of point-sets, convex hull and algorithms. Conics and quadrics, implicit and parametric forms, computation of intersections.

Lecture 4: Interpolating and Approximating Splines: Cubic splines, Bezier curves, B-splines

1 Introduction 4.1

In the last lecture we saw that curves can be represented conveniently in para-

metric form. Eg in 2D

¡£¢¥¤§¦©¨ ¢ ¢ ¤¦¢ ¤¦¦ and we saw some “regular” curves like ellipses, and so on.

In this lecture we introduce how to build “irregular” shaped curves in a piece- wise fashion out of splines.

Splines are widely used in graphics and CAD — indeed one of the pioneers of their computational use, Pierre Bezier´ , developed his ideas while working for in the 1970’s.

Example of an interpolating spline 4.2

An idea of what were are about can be gained by considering the following prob- lem How should one specify the path of a road through a number of villages ...

Roads made up of separate functions ¡ .

    

¢¤ ¦¨¡ ¢¤ ¦

Continuous ¡

 

¡! ¢¤ ¦¨¡" ¢¤ ¦  

Smooth 

¡ ¢¤$%¦©¨¡ ¢¤$%¦

# #   Cont 2nd d?  These are interpolating splines, because they actually go through the points. Later we will see approximating splines, where the points are control points, which define the shape of the , but do not necessary lie on the curve.

Other constraints might be applied ... Eg, need to have particular orientation to meet other roads, rivers at right angles ...

2

Parameterization 4.3

¤ 

Convenient to use as a global ¤ parameter along the entire curve, and xi P P i+1 as a local parameter running from 0 to 1 0 Pi between points.

That is, within spline & , the local p=0 p=1 parameter is P P

1 p p m

¤)( ¤$

 i i+1

¤'¨

¤$ *( ¤$

Polynomials provide usable functions for the splines... But what degree to use ? Linear? — a “Roman Road” spline, so not smooth! Quadratic? — let’s see ...

Quadratic splines? 4.4

¢+¤ ¦ ¡,¨ ¢- .¢¤/¦01¢+¤ ¦1¦ Think just with the part of 

Using the global parameterization Using the local parameterization

32 ¨ 465879¤$2.5;:<¤/= 32 ¨ 4

2

=

> ¨ 465879¤!5;:<¤ > ¨ 465A7B5A:



2

¨ 758?@:<¤ ¨ 7  

2 2

This suggests: 1st choice

2

C 2 y

Choose gradient at D . 0

2 

  2nd choice

Use gradient and , to fit quadratic. y  



This fixes gradient at D . 2

 > 

 Gradients Use gradient and , = to fit next y

equal

... and so on ... 1

... Then repeat for part ... p p p 0 1 2 So for a continuous, smooth quadratic spline simply choose of gradient at the first (or any one) point, and the entire curve is fixed.

Too sensitive to choice of gradient. Likely to oscillate.

3 Cubic splines 4.5

Now consider just the local parameterization of the & th cubic spline sequence.

Again, we just look at  — similar equations are written for — but you should

  7

realize that the 4 , , etc are different.

    

=

 ¢¥¤§¦ ¨ 4 5A7 ¤E5;: ¤ 5GF ¤$H

I

 

 ¢KJL¦ ¨ 4

@¢1MN¦ ¨ 4O95A7P95A:Q95GFO

 ¢KJL¦ ¨ RS¨T7P



 ¢1MN¦ ¨ RS B¨U7P95V?@:QW58XYFO 

Re-arranging, and writing 3Z¢[M\¦©¨@  ,

4O¨ @

7P¨ R]

:Q¨ X/¢%@¥ ^(_@%¦.(8?ORS/(ARS 

      

F ¨ (`?$¢% (a ¦!5VR 5VR

We make the derivative equal at the junction of two splines. The is called Hermite

5cM b . So, for a b segment spline, there are degrees of freedom.

How are the derivatives specified? 4.6

1. By external constraints (eg, the perpendicular road)

2. Automatically:

ed$   

  

For example, fit parabola to , , ,

  R

and use value of gradient at  as the gradient .

2

R ¨cJ RSfG¨TJ Also need to choose end point gradients: eg, set and . 3. But, we could ask the 2nd derivatives to match as well. This is a natural cubic spline.

4 Natural cubic splines 4.7

Try a counting argument to show that we have sufficient d.o.f.

Again we think only about the  cubic: the cubic is similiar.

2

f

D D

Each of the b segments between and requires 4 parameters to specify the

I g 

cubic in . b UNKNOWNS. (UM

At each of b internal points on spline

@ed$0¢[M\¦B¨hi iZ¢jJC¦B¨hi   ¢[M\¦B¨h ¢[M\¦k¨U ¢jJC¦ ¢jJC¦

# l

ed$ ed$  

I g

¢ (hM\¦

b CONSTRAINTS

At the end points

@2m¢jJC¦©¨h@2  ¢[M\¦B¨h  

f f I

? CONSTRAINTS

g g

(8?on b Now, b so we can do it! The extra two degrees of freedom are setting the second derivatives at the end

points:

 ¢jJC¦B¨TJ  ¢1MN¦©¨TJ

l l

2

f I ? CONSTRAINTS

Computing Natural Cubic Splines 4.8

g g

p b Don’t solve for the cubic splines by inverting a b matrix. Instead ... Basic equations

Leads to

    = 

 ¢¥¤§¦ ¨ 4 5G7 ¤E5A: ¤ 5AF ¤$H

 

4 ¨ 

  

 ¢¥¤§¦ ¨ 7 58?@: ¤E58XYF ¤/=



 

7 ¨ R

#

 ¢¥¤§¦ ¨ ?i:Q]58qYFOr¤



:Qh¨ X/¢%@ (ti-¦ (A?ORS/(8RS 

¤s¨ J ¤,¨ M (`?$¢%i (t@%¦58RS<5uRS  Put in and into the first two FOh¨

on the left.

¤v¨ M ¢ (UM\¦ ¤w¨cJ &

Now equate the 2nd derivs ( for the & th section, for the th ...

?@:Qed$"5GqYFOed$ ¨ ?i:Q

I

?$xyX/¢%@<(tied$z¦.(G?OR]{d$^(8RS{|5 q}x¥(`?<¢-i<(t@ed$z¦!58R]ed$"58R]~|

¨ ?

I g

R]ed$5 R]W5uRS  ¨ X}¢-i (tied$z¦

5 Computing Natural Cubic Splines, ctd 4.9

To repeat

g

ed$  ¥    ed$

R 5 R 5uR ¨TX/¢% (a ¦

2  2 2 

C # ¢KJL¦©¨TJ : ¨TJ X/¢% (a ¦.(8?OR (AR ¨cJ

At the first point, 2 . So and , so

2   2

?OR 5uR ¨UX/¢% (t ¦

 ¢[M\¦©¨TJ ?@: 5GqYF ¨TJ

l f f

Similarly for the end section f , so from which

R d$!5u?OR ¨UX/¢% (a d$[¦

f f f f

€ €

Gather all this together€

ƒ „ ƒ „ ƒ „

R]2 X/¢%>*(t@20¦ ? M

„ „ „

„ „ „

  

„ „ „

g

R‡ X/¢% (t@20¦ M M

  

„ „ „

  

„ „ „

=

  „ „ „ 

g

R X/¢% (tC1¦ M M

  „ „ „ 

  „ „ „ 

=

H

¨

  

„ „ „

  

„ „

. „ . .

  

„ „

. „ . .

 

 . . .

  

g

d$ d

M M R]f X}¢-if,(t@f ¦

‚ ‚ ‚

=

† † †

d$

M ? RSf X}¢-if,(t@f ¦

Computing Natural Cubic Splines, ctd 4.10

€ €

Use row ops to simplify€ further to

„ „ „

ƒ ƒ ƒ

‰

R]2 M ˆC2 2

„ „ „

„ „ „

  

„ „ „

‰

R‡ M ˆ$ 

  

„ „ „

  

„ „ „

  

„ „ „

‰

R M ˆ

  „ „  „

  „ „  „

= = =

¨

  „ „  „

  

„ „

. „ . .

  

„ „

. „ . .

 

 . . .

  

d$ d$

M ˆLf R]f

‚ ‚ ‚

  

† † †

‰

M RSf f

R R d$ f Then back substitute to find f , and so in reverse order.

Having got the R ’s substitute in to

 

4 ¨ 

 

7 ¨ R

:Q¨ X/¢%@¥ ^(_@%¦.(8?ORS/(ARS 

FO¨ (`?$¢%i *(ai-¦!5VRS95VRS 

6

Approximating curves as opposed to interpolating 4.11

¢%Š"¦1"¢%Š¦ Š In 2D each a in .

Local control of curve.

Important examples are Bezier´ curves and B-splines.

Used in graphics, CAD, drawing packages ...

Bezier´ curves 4.12

Bezier curves were one of the earliest spline curves. The curves were originally devised using the de Casteljau construction.

First consider a Bezier curve of degree 1, 

2 x1 D

between D and

2 

¡,¨ ¢[M‹(tŠ¦Œ¡ 5;Š/¡

x (1−u)

21#Œ D Now consider three control points, = x0

and set u

Ž

¨ ¢[M‹(tŠ¦Œ¡!2 5;Š/¡.

2 x1

Ž

 ¨ ¢[M‹(tŠ¦Œ¡."5;Š/¡

= a

Ž Ž

2 

¨ ¢[M‹(tŠ¦ 5tŠ ¡ 1 a 0 Then ¡ follows a quadratic Bezier curve x

0 x x

¡s¨ ¢[M(aŠ¦ ¡!2.5u?iŠk¢[M‹(_Š"¦Œ¡.5GŠ ¡ =

= 2 =

7

Carrying on ... 4.13

2l 

D =

Now consider four control points, H and set

Ž

2 2 

¨ ¢1M(_Š"¦Œ¡ 5tŠ}¡

x x 2

Ž

¨ ¢1M(_Š"¦Œ¡.!5tŠ}¡  1

= u

Ž

¨ ¢1M(_Š"¦Œ¡ 5tŠ}¡

= =

H u = 1

‘

Ž Ž

¨ ¢1M(_Š"¦ 2 5GŠ 

2 u = 0

‘

Ž Ž

¨ ¢1M(_Š"¦ "5GŠ

 x0 x 3

=

‘ ‘

2 

¡ ¨ ¢1M(_Š"¦ 5GŠ

Then ¡ follows a cubic Bezier curve

2 =  =

¡£¢%Š"¦B¨ ¢- .¢%Š¦¢%Š"¦1¦z’“¨ ¢[M (oŠ"¦HŒ¡ 5”X3Š.¢[M ( Š¦ ¡ 5”X3Š ¢1M/( Š¦¡ 5)Š/Hz¡ J ˜™Šš˜ M

= HT•%–Y—

Bezier´ curves of degree 3 4.14

2 

¡£¢%Š¦©¨ ¢[M(aŠ¦ ¡ 58X@Šk¢[M‹(aŠ¦Z=Z¡ 5AX3Š§=N¢[M‹(tŠ¦Œ¡ 5;Š ¡ J ˜™Šš˜ M

H H

=

H •%–Y—

Properties

›¡£¢jJC¦B¨¡!2 ¡£¢[M\¦©¨™¡

and H , so that a Bezier´ curve interpolates its end control

points.2Ÿ ¨cX/¢¡¡.^(¢¡2¦

EœŒiž . Geometric œŒ significance? The curve lies inside the convex hull of its control points. The control points need not be planar. Is it always smooth It can have inflections. It can self-cross.

8

Blending functions — actually Bernstein functions 4.15

2 

¡£¢%Š"¦B¨ ¢[M(aŠ¦ ¡ 58X3Š.¢[M‹(aŠ¦Z=Z¡ 58X@Š§=N¢[M‹(tŠ¦Œ¡ 5;Š ¡

H H

= H

One can think of the coefficients of the control points as blending functions

Š¤£ ¢1M¥(tŠ"¦ These are symmetric under . 1

3 3 ( 1 - u ) u

3 u 2 ( 1 - u )

3 u ( 1 - u ) 2

0 0 1

Bezier´ curves of degree ¦ 4.16

The de Casteljau construction can be expressed as

d

© © ·Y¸$¹ ¨

¢-Š¦Œ¡ ¢%Š¦©¨ °±‡² ³ ´µ¶¢[M(aŠ¦ Š J ˜™Šš˜ M ¡£¢%Š¦©¨ §

© © ¬®­<¯ ¯ ©

§

—

2<« «

©+ª ¨TX

e.g. for ² (cubic Bezier):´

2

¢-Š¦ ¨ ¢1M(_Š"¦

H

«

 =

¢-Š¦ ¨ X/¢[M‹(tŠ"¦ Š

«

¢-Š¦ ¨ X/¢[M‹(tŠ"¦Š =

=

«

¢-Š¦ ¨ Š

H

H «

Note that (what is the geom significance?)

¨ ·Y¸$¹

§ ¢-Š¦©¨ ¢¡Šo5º¢[M‹(tŠ¦1¦ ¨ M ¢-Š¦¥»hJ J‡˜™Šš˜ M

© ©

§

•%–Y—

« «

2 ©+ª

9 Matrix form 4.17

Another representation is

¡!2 M

°¼ ´%½ °¼ ´%½

¼ ½ ¼ ½

¡. (ÀX

¼ ½ ¼ ½

2  2 =

¡£¢%Š"¦B¨ ¢ ¢%Š¦ ¢%Š"¦ ¢%Š"¦ ¢-Š¦1¦ ¼ ½ ¢%Š¦©¨ ¢[M‹(tŠ¦H¥¨ ¾MŠ‡Š Š/H[¿ ¼ ½

¼ ½ ¼ ½

=

H

¡ 5`X

« « « « «

¼ ½ ¼ ½

=

± µ ± µ

¡ (EM H

Collecting these together: €

„

ƒ

„ 2

M J J J ¡

„

°¼ ´%½



„

¼ ½



„ 

(ÁX X J J ¡

¼ ½



„

¾ = ¿

¼ ½ ¡¥¢%Š¦ ¨ MŠ‡Š Š/H



¼ ½



X (Áq X J ¡

¼ ½

‚



=

± µ

†

(ÂM X (ÀX M ¡

H

¨ ÃTÄWÅYÆ%Ç-ÈlÆ-É Ê Ä ÅYÆ%Ç-ÈlÆ-É is the Bezier basis matrix for order 3.

Example 4.18

Where is ¡£¢jJ<Ë ÌO¦ ?

€

ƒ „

„

M J J J ¡!2

„

° ´

¼ ½



„

¼ ½

M M M M



„

(ÀX X J J ¡.

¼ ½



„

¡¥¢ ¦ ¨ Í3M ¼ ½



¼ ½

Î/Ï

g



X (Àq X J ¡

? ?

¼ ½

‚



=

± µ

†

(EM X (ÀX M ¡

H

¡2

° ´

¼ ½

¼ ½

M X X M M

¡k

¼ ½

¢zM¥XÀXEMN¦ ¼ ½ ¨ ¡!2.5 ¡."5 ¡ 5 ¡ ¨

¼ ½

Î Î Î Î Î

=

H

¡

¼ ½

=

± µ

¡ H

So, it is a “centre-weighted centroid”.

10 Parametric surface (Tensor Product) 4.19

We would like to represent a surface using control points and blending functions,

in the same manner as a curve

¨

¢%Š¦¡ ¡£¢%Š¦©¨ ¢- ¢-Š¦¢%Š"¦PÐ/¢%Š"¦1¦z’”¨

© ©

« ©

For a surface, we need two parameters:

¨

 ¢%Š*Ñ<¦Œ¡  ¡£¢%Š*Ñ<¦©¨ ¢- ¢%Š^1Ñ$¦1"¢%Š*Ñ<¦QÐ/¢%Š*1Ñ<¦1¦Z’‡¨

f f

© ©

f

©Ò

¡  f with © a grid of 3D points.

Natural choice



f ¢%Š^1Ñ$¦k¨ fÁ¢%Š¦ ¢%Ñ<¦

© ©

« « Ò

This is simply a “product” of Bezier´ curves

¨ ¨

 Í

¢%Ñ<¦¡"f ¡£¢-Š*Ñ<¦k¨ f®¢%Š"¦

© ©

Ï

f

« « ©

The 16 control points for a Bezier´ bicubic patch 4.20

¨



¡£¢%Š^1Ñ$¦k¨ f®¢-Š¦ ¢%Ñ$¦Œ¡"f

© ©

f

« « © u = 1 v = 0 20 u = 0 v = 0 10 30 11 31 21 00 01 22 12 32 02 v 13 23 33 u = 1 v = 1 03 u u = 0 v = 1

Properties

›¡£¢jJ<PJC¦B¨™¡21 2+^¡£¢KJ9mM\¦k¨¡!2 ËNË+Ë

H so that corners are pinned.

Convex hull property

¨ ¨ ¨ ¨

§ §  ° § ´ ° § ´

f ¢-Š*Ñ<¦k¨ ± f®¢-Š¦ µ ± ¢-Ñ<¦ µ,¨ M

© ©

2 2 2<« 2<«

f f

Ò

ª ©+ª ª ©+ª

11

Another way of picturing the process 4.21

¡£¢%Š^1Ñ<¦›¨ Ó ¢%Š"¦!¢%Ó ¢%Ñ$¦Œ¡  ¦

f f f

© © © « You might prefer to look at the expression « in a

rather different way.



¨TJ<mM@0?WPX¢ ¢%Ñ<¦Œ¡"f ¦

Ó

© © © b Then construct a Bezier curve out of

For « for

J ˜ѓ˜ M M

J ˜™Ñv˜ defines four separate Bezier these for — ie

¢-Š¦!¢ ¢%Ñ<¦Œ¡  ¦

ÓÔf f Ó f

Ñ

© © © « curves, each parallel to the axis. « . u u 20 20 10 10 30 30 11 31 11 31 21 00 01 21 00 01 22 22 12 32 12 32 02 02 v 13 23 v 13 23 33 33 03 03 Choose a value of Ñ and you have four Then pick a point on this curve by points on these curves. choosing Š .

Matrix form 4.22

Another representation is using matrices. Recall ¡£¢-Š¦©¨™ÃSÄÕÊ .

g`Ø

¡¥¢%Š*Ñ<¦k¨VÃÂÄÕÖ6Ä

’E×$’

–W–YÙ}Ú

€ „

where ƒ

„

¡21 2 ¡21#T¡!2 ¡!2

„

=

H



„



„

¡kŒ 2 ¡kŒ#T¡. ¡.



„

=

H

¨ M£Ñ`Ñ>= Ñ Ö‡¨

× ¾ H[¿





¡  2 ¡ #T¡  ¡ 

‚



= = = = =

H

†

  #  2

¡ ¡ ¡ ¡

=

H H H H H

12 Graphics application of Bezier´ tensor product surface 4.23

More teapots ... 4.24

13 Other properties of Bezier curves 4.25

Switching to higher degree A Bezier curve of degree ² is also a Bezier curve of

¨ 5UM

²

degree ² .

5cM 5V? ² This means that the ² control points can be replaced by control points in different positions and the curve shape remains unchanged, and hence one can increase the degree arbitrarily. Here are the expressions for moving the control points to increase the degree by 1.

Degree 7

¡ ¨ ¡!2

2

& &

¡ ¨ ¡!{d$"5 Í3M( ¡"



Ï

5TM 5TM

² ²

¨ M3+ËNË+Ë0 &

² Degree 4

¡ ¨ ¡

 

§ §

Piecewise Bezier curves 4.26

Suppose we require many control points ...

Piecewise Bezier´ curves

Need an extra point inserted midway. This will be a point of inflexion.

14 B-Splines 4.27

Like draftsperson’s spline, but approximating.

A B-spline consists of several curve segments, each represented by a polyno-

mial.



= Û

Controlled smoothness: e.g. cubic B-splines are Û , or can be made to be less: 2

or Û . Key advantage:

Local control: moving a control point only affects part of the curve.

This isn’t the case with a Bezier curve of high degree. But often it is said not to be the case with, say, cubic Bezier curves. But introducing the “extra” points does provide decoupling ...

Example - a cubic B-spline 4.28

2 

f

5cM ¡ [¡ NË{Ë~Ë{[¡ »hX b

b control points, , with .

(8?  +Ë{Ë{Ë~

f

b Ü ÜYÝ Ü

cubic polynomial curve segments H .

Each curve segment is defined as €

ƒ „

g

ed „

¡ M M J

„

H

° ´

¼ ½

 „

¼ ½

M

 „

ed

¡ (ÁX J X J

¼ ½

 „

=

¡"Z¢%Š"¦B¨ Mފ Š Š Ö ¼ ½ Ö)¨

¾ = ¿

H



¬®ß¥àP­

¼ ½



¡"ed$ X (Áq X J

q

¼ ½

‚



± µ

†

¡! (ÂM X (ÁX M

2

f

Ö ¡ ¨h¡

If the spline is closed then is the same for all curve segments and . Ö If the spline is open then the matrices can be modified at the curve ends so that the curve segments interpolate the end control points.

15 B-splines, ctd 4.29

x1 x 2 x5 join x 0 join x4

x3

2 

¡ 1¡ 1¡ 1¡ =

—– influenced by H

¡ 1¡ 1¡ 1¡á

Ý = —– influenced by H Convex hull property

Spline demo: http://www.geocities.com/msheinrichs/curve.html

Tracking application of B-splines 4.30

Used in computer vision as “Active Contours”. Here the local control is a bonus.

See Blake and Isard “Active Contours” Springer 1999.

16