Parametric representation of curves

9. Parametric curves
CS527 Computer Graphics
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
P ( n) =
n
∑C u
k
k
k =0
(n+1) degrees of freedom.
1
9. Parametric curves
CS527 Computer Graphics
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.
1
 P0  
  1
 P1  
 P2  = 
  1
 P3  
  
1
0
1
3
2
3
1
0
2
1
 
 3
2
2
 
3
1
0 
3 
 1   C 0 
 
 3   C1 
3
 2   C 2 
   
 3   C 3 
1 
P3
P1
P2
P0
0
"
u
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.
2
9. Parametric curves
CS527 Computer Graphics
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
3
For a parametric cubic curve, Q(u ) = ∑ c i u i ,
(9-1)
i =0
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)
3
9. Parametric curves
CS527 Computer Graphics
Q(u
R0
R3
p3
p0
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
∴
Q ' (u) = [ 0 1 2u 3u 2 ] c
so
(9-4)
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:
p 
 p0 
 3
R 
 0
R 
 3
=
1


1

0

0

0 0 0  c0 
1 1 1 c1 
  
1 0 0  c2 
 
( 9 - 5a )

1 2 3 c3 
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,
MH =
∴
 1


0

- 3

 2

0
0
0
3
1
-2
-2
1
0


0 

- 1

1 
c = MH qH
4
9. Parametric curves
CS527 Computer Graphics
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:
where
Q(u) = U MH qH
bH = U MH

( Hermite Blending function )
= 1 u u 2

= bH qH
1


3  0
u  
 - 3

2

0
0
3
0 0 
1 0 

- 2 - 1
-2
1

1 
= [ (2u3 - 3u2 + 1) (-2u3 + 3u2) (u3 - 2u2 + u) (u3 - u2) ]
= [ b0(u) b1(u) b2(u) b3(u) ]
∴ Q (u) =
3
∑
i =0
0 ≤ u ≤ 1
b i (u) qHi
( 9 - 6b )
Hermite Blending function
b0(u) b1(u) b2(u) b3(u): are called Hermite cubic basis or blending function.
1.0
P2(1)
1.0
b1
u
b2
0
1.0
b3
•The Hermite cubic curve is therefore a weighted sum of the elements of qH , i.e.
Q (u) =
3
∑
i =0
b i (u) qHi
0 ≤ u ≤ 1
•b1 (u) = 1 - b0 (u)
•b0, b1 >> b2, b3 .
⇒ endpoints more influence than TVs.
5
9. Parametric curves
CS527 Computer Graphics
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:
k
∑
i =0
b i (u) = 1
bi (u) ≥ 0 ,
u ∈ [ 0, 1 ]
for all i
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
( 9-7 )
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
6
9. Parametric curves
CS527 Computer Graphics
Q' (1) = 3( p3 - p2 ) = c1 + 2c2 + 3c3
p2 = [ 1 2/3 1/3 0 ] c
In matrix form:
p 
1
0
0 0 c0  
 0


p 
 c  

1
1/3
0
0
 1
  1  

=





 p2 
1 2/3 1/3 0   c2  


   

 c 
p 
1
1
1
1
   3  

3




or
p = Mc
MB = M -1
and
MB M = I
Thus,
MB =
=
M− 1
1


- 3

3

- 1

0
3
-6
3
0
0
3
-3
0
0

0

1











p =
and
p0 

p1 

p 2 

p3 
And, c = MB p
Q (u) = U c = U MB p
= 1 u u 2

1


3  - 3
u 
3

- 1

0
3
-6
3
Q (u) = U MB p = bB p
0  p0 
0  p1 


3 0  p2 


- 3 1  p3 
0
0
( 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
Q (u) =
n
∑
i =0
pi B i,n (u) ,
0 ≤ u ≤ 1
( 9 - 10 )
where
p i are the control points,
B i,n ( u ) are Bezier blending function (or Bernstein polynomial)
B i,n ( u ) = nCi u i (1- u) n- i
( 9-11 )
n
n
where Ci is the binomial coefficient, Ci = n! / i! ( n - i )!
The curve segment so generated satisfies the convex hull properties.
For cubic curve, n = 3.
7
9. Parametric curves
n
CS527 Computer Graphics
Ci = 3Ci = 3! / i! ( 3 - i )!
B0,3 ( u )
B1,3 ( u )
B2,3 ( u )
B3,3 ( u )
=
=
=
=
1 . u0 ( 1 - u ) 3 = ( 1 - u ) 3
3u ( 1 - u ) 2
3( 1 - u ) u2
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.
1.
1.
bB0(u)
bB3(u)
bB2(u)
bB1(u)
Note:
u
0
3
∑
i =0
b Bi (u) = 1
0.
1.
Domain space
u
for all i
Object space
8
9. Parametric curves
CS527 Computer Graphics
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)
p1(1)
P (2)
•C 1 continuity:
p1(2) - p0(2) = p3(1) - p2(1)
p1(2) = 2 p3(1) - p2(1)
or p3(1) = ½ ( p1(2) + p2(1) )
1
(9 -14)
Q(1) (u)
p0
•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)
(1)
P2(2)
Q(1) (u)
P0(2 ) = P3( 1)
P2(1)
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:
pir (u) = ( 1- u ) pir-1 (u) + u pi+1r-1 (u)
where for each r = 1, …, n, i = 0,…, n – r,
pi0 (t) = pi
( 9-16 )
Then a point on the curve with parameter value u is given by p0n (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) = p03 (u).
r = 1,
p01 (u)
p11 (u)
p21 (u)
i = 0,.., (3-1).
= ( 1- u ) p0 + u p1 = L1
= ( 1- u ) p1 + u p2 = H
= ( 1- u ) p2 + u p3 = R2
r = 2, i = 0, (3-2).
p02 (u) = ( 1-u ) p01 (u) + u p11 (u) = L2
p12 (u) = ( 1-u ) p11 (u) + u p21 (u) = R1
9
p3(2)
9. Parametric curves
CS527 Computer Graphics
r = 3, i = (3-3).
p03 (u) = ( 1- u ) p02 (u) + u p12 (u) = L3
Substitute p02 (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:
p1
P0L1/ L1P1 = P1H/ HP2 = P2R2/ R2P3
= L1L2/ L2H = HR1/R1R2
= L2L3/ R0R1 = u / (1-u )
then, with u=0.615:
L3 = R0
= p03 ( 0.615)
= Q (u= 0.615).
L2
L1
H
p2
R1
L3 = R0
u
R2
p0 = L0
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 ) p01 (u) + u p11 (u)
= ( 1- u )2 p0 + 2u ( 1-u ) p1 + u 2 p2
L3 = ( 1- u ) p02 (u) + u p12 (u)
= ( 1- u )3p0 +3u ( 1-u )2p1+3u2( 1-u ) p2+ u3p3
L   1
 0 
 L   (1 − u )
 1 = 
 L  (1 − u )2
 2 
 L  (1 − u )3
 3  
1
So, DL (u) =
B
Similarly:
DBR (u) =

 (1 − u )

(1 − u) 2

(1 − u )3

(1 − u)3

 0


 0

 0
0
0
0   p0 
  
u
0
0   p1 
⋅ 
2u(1 − u)
u2
0   p2 

2
2
3
3u(1 − u) 3u (1 − u) u   p3 
0
0
0

u
0
0

2
2u (1 − u )
u
0

3u(1 − u )2 3u 2 (1 − u ) u 3 
3u(1 − u)2
(1 − u)2
0
0
( 9 - 18a )
3u 2(1 − u) u 3 
2u(1 − u)
(1 − u)
0
u 2 
u 
1 
( 9 - 18b )
Suppose set u=1/2 to generate the left half curve and right half curve.
10
9. Parametric curves
CS527 Computer Graphics
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
Thus
f(u+δ) = f(u) + ∆f(u)
or in iterative form:
( 9-21 )
11
9. Parametric curves
fk+1 = fk + ∆fk with
CS527 Computer Graphics
uk+1 - uk = δ = constant
For a polynomial of degree 3:
f (u) = c0 + c1u + c2u2 + c3u3
( 9-20 )
2
2
3
∆f(u) = 3c3 u δ + u(3c3 δ + 2c2δ) +c3 δ + c2 δ 2 + c1 δ ( 9-22 )
∆ 2f(u) = ∆(∆f(u)) = ∆ f(u+δ) – ∆ f(u).
( 9-23 )
2
2
3
2
∴ ∆ f(u) = 6c3 δ u + 6c3 δ + 2c2 δ
( 9-24 )
3
2
2
similarly, ∆ fk = ∆ fk+1 - ∆ fk
or
∆ 3f(u) = ∆(∆2f(u)) = 6c3 δ 3
( 9-25 )
rd
i.e. the 3 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 ,
fk+1 = fk + ∆fk
∆ 3fk = 6c3 δ
3
( 9-26 )
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,22,24,25):
∆ 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-26 ).
The evaluation of Q(u) therefore needs only 9 additions for each 3D point. But it applies
to only uniform steps in u, and is prone to accumulation of numerical errors.
Forward differencing uses fixed subdivision in rendering the curve.
Recursive evaluation method for Bezier curve:
•recurvsive subdivision avoids unnecessary computation, but takes time to test for
flatness.
•de Casteljau algorithm subdivide a Bezier curve anywhere along its length into two
smaller curves, each with their respective distinct control polygons.
•repeating subdivision produces closer approx. to the curve. Termination criterion can be
based on a linearity test applied to the convex hull, simple for a Bezier curve. How?
12
9. Parametric curves
CS527 Computer Graphics
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 ( );
13