Graphics
Parametric Curves
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Overview
CGVR
Introduction to mathematical splines Bezier curves Continuity conditions (C0, C1, C2, G1, G2) Creating continuous splines
C2-interpolating splines B-splines Catmull-Rom splines
Graphics Lab @ Korea University
Introduction
Mathematical splines are motivated by the “loftsman’s spline”:
CGVR
Long, narrow strip of wood or plastic Used to fit curves through specified data points Shaped by lead weights called “ducks” Gives curves that are “smooth” or “fair”
Such splines have been used for designing:
Automobiles Ship hulls Aircraft fuselages and wings Graphics Lab @ Korea University
Requirements
CGVR
Here are some requirements we might like to have in our mathematical splines:
Predictable control Multiple values Local control Versatility Continuity
Graphics Lab @ Korea University
Mathematical Splines
The mathematical splines we’ll use are:
CGVR
Piecewise Parametric Polynomials
Let’s look at each of these terms…
Graphics Lab @ Korea University
Parametric Curves
CGVR
In general, a “parametric” curve in the plane is expressed as:
x = X (t)
y = Y (t )
Example: A circle with radius r centered at the origin is given by:
x = r cos t
y = r sin t
By contrast, an “implicit” representation of the circle is:
x +y =r 2
2
2 Graphics Lab @ Korea University
Parametric Polynomial Curves
A parametric “polynomial” curve is a parametric curve where each function x(t), y(t) is described by a polynomial: n
x = ∑ ai t
i
i =0
CGVR
n
y = ∑ bi t
i
i =0
Polynomial curves have certain advantages
Easy to compute Infinitely differentiable
Graphics Lab @ Korea University
Piecewise Parametric Polynomial Curves
A “piecewise” parametric polynomial curve uses different polynomial functions for different parts of the curve
CGVR
Advantage: Provides flexibility Problem: How do you guarantee smoothness at the joints? (Problem known as “continuity”)
In the rest parts of this lecture, we’ll look at:
Bezier curves – general class of polynomial curves Splines – ways of putting these curves together
Graphics Lab @ Korea University
Bezier Curves
CGVR
Developed simultaneously by Bezier (at Renault) and by deCasteljau (at Citroen), circa 1960 The Bezier Curve Q(u) is defined by nested interpolation:
Q( u ) = ∑ Vi Bi , n ( u ) , n
i =0
0 ≤ u ≤1
Bi ,i = u i , B0,i = (1 − u ) Vis are Bi , n“control = (1 − u ) B points” i , n −1 ( u ) + uBi −1, n −1 ( u ) ,
i
1≤ i < n
{V0, …, Vn} is the “control polygon”
Graphics Lab @ Korea University
Example: Bezier Curves Q( u ) = ∑ Vi Bi , n ( u ) , n
i =0
n = 1, Q( u ) = V0 B0,1 ( u ) + V1 B1,1 ( u )
CGVR
0 ≤ u ≤1 Bi ,i = u i
= V0 (1 − u ) + V1u n = 2, Q( u ) = V0 B0, 2 ( u ) + V1 B1, 2 ( u ) + V2 B2, 2 ( u )
B0,i = (1 − u )
i
= V0 (1 − u ) + V1 B1, 2 ( u ) + V2 u 2 Bi , n = (1 − u ) Bi , n −1 ( u ) + uBi −1, n −1 ( u ) 2
B1, 2 ( u ) = (1 − u ) B1,1 ( u ) + uB0,1 ( u ) 2 = V0 (1 − u ) + V1 2(1 − u ) u + V2 u 2
Graphics Lab @ Korea University
Bezier Curves: Basic Properties
CGVR
Bezier Curves enjoy some nice properties:
Endpoint interpolation:
Q( 0 ) = V0
Q(1) = Vn
Convex hull: The curve is contained in the convex hull of its control polygon Symmetry:
Q(u) is defined by {V0, …, Vn} ≡ Q(1-u) is defined by {Vn, …, V0}
Graphics Lab @ Korea University
Example: 2D Bezier Curves
CGVR
Graphics Lab @ Korea University
Bezier Curves: Explicit Formulation
CGVR
Let’s give Vi a superscript Vij to indicate the level of nesting An explicit formulation Q(u) is given by the recurrence:
Vi = (1 − u )Vi j
j −1
j −1 i +1
+ uV
Graphics Lab @ Korea University
Explicit Formulation (cont.)
CGVR
For n=2, we have: Q( u ) = V02 = (1 − u )V01 + uV11
[
] [
= (1 − u ) (1 − u )V00 + uV10 + u (1 − u )V10 + uV20 = (1 − u ) V00 + 2u (1 − u )V10 + u 2V20
]
2
In general:
n i n −i Q( u ) = ∑ Vi u (1 − u ) i =0 i n
Bin ( u )
Bin ( u ) is the i ‘th Bernstein polynomial of degree n Graphics Lab @ Korea University
Example: Explicit Formulation
CGVR
n i n −i Q( u ) = ∑ Vi u (1 − u ) i =0 i n
For n = 3,
Q( u ) =3 C 0 (1 − u ) V00 +3 C1u (1 − u ) V10 +3 C 2 u 2 (1 − u )V20 +3 C3u 3V30 3
2
Q( u ) = V03
= (1 − u )V + uV 2 0
2 1
[ ] [ ] = (1 − u ) [(1 − u ) {(1 − u )V + uV } + u{(1 − u )V + uV }] + u [(1 − u ) {(1 − u )V + uV } + u{(1 − u )V + uV }] = (1 − u ) (1 − u )V + uV + u (1 − u )V + uV 1 0
1 1
1 1
1 2
0 0
0 1
0 1
0 2
0 1
0 2
0 2
0 3
= (1 − u ) V00 + 3(1 − u ) uV10 + 3(1 − u )u 2V20 + u 3V30 3
2
Graphics Lab @ Korea University
Bezier Curves: More Properties
CGVR
Here are some more properties of Bezier curves
n i n −i Q( u ) = ∑ Vi u (1 − u ) i =0 i n
Degree: Q(u) is a polynomial of degree n Control points: How many conditions must we specify to uniquely determine a Bezier curve of degree n
Graphics Lab @ Korea University
More Properties (cont.)
Tangent:
CGVR
Q ′( 0) = n(V1 − V0 )
Q′(1) = n(Vn − Vn −1 )
k ‘th derivatives: In general,
Q(k)(0) depends only on V0, …, Vk
Q(k)(1) depends only on Vn, …, Vn-k
At intermediate points every derivative
, all control points are involved
Graphics Lab @ Korea University
Explanation
CGVR
n i n −i Q( u ) = ∑ Vi u (1 − u ) i =0 i n
= n C0 (1 − u ) V0 + n C1u (1 − u ) n
Q ′( u ) = − n n C 0 (1 − u )
n −1
n −1
V1 + + n C n −1u n −1 (1 − u )Vn −1 + n C n u nVn
V0 + n C1 (1 − u )
n −1
V1 −( n − 1) n C1u (1 − u )
n−2
V1
+ +( n − 1) n C n −1u n − 2 (1 − u )Vn −1 − n C n −1u n −1Vn −1 + n n C n u n −1Vn
Q ′( 0 ) = − n n C 0 (1 − 0 )
n −1
V0 + n C1 (1 − 0 )
n −1
V1
= − nV0 + nV1 = n(V0 − V1 )
Q ′(1) =− n C n −11n −1Vn −1 + n n C n 1n −1Vn = − nVn −1 + nVn = n(Vn − Vn −1 )
Graphics Lab @ Korea University
Cubic Curves
For the rest of this discussion, we’ll restrict ourselves to piecewise cubic curves
In CAGD, higher-order curves are often used
Gives more freedom in design Can provide higher degree of continuity between pieces
For Graphics, piecewise cubic lets you do about anything
CGVR
Lowest degree for specifying points to interpolate and tangents Lowest degree for specifying curve in space
All the ideas here generalize to higher-order curves Graphics Lab @ Korea University
Matrix Form of Bezier Curves
CGVR
Bezier curves can also be described in matrix form: 3 3 i 3−i Q( u ) = ∑ Vi u (1 − u ) i =0
i
= (1 − u ) V0 + 3u (1 − u ) V1 + 3u 2 (1 − u )V2 + u 3V3 3
= u3
[
u2
[
u2
= u3
2
3 −3 1 3 −6 3 u 1 − 3 3 0 0 0 1 V0 V u 1 M Bezier 1 V2 V3
]
1 V0 0 V1 0 V2 0 V3
]
Graphics Lab @ Korea University
Display: Recursive Subdivision
CGVR
Q: Suppose you wanted to draw one of these Bezier curves – how would you do it?
A: Recursive subdivision
Graphics Lab @ Korea University
Display (cont.)
CGVR
Here’s pseudo code for the recursive subdivision display algorithm Procedure Display({V0, …, Vn}) Display if {V0, …, Vn} flat within e then Output line segment V0Vn else Subdivide to produce {L0, …, Ln} and {R0, …, Rn} Display({L0, …, Ln}) Display Display({R0, …, Rn}) Display end if end procedure
Graphics Lab @ Korea University
Splines
CGVR
To build up more complex curves, we can piece together different Bezier curves to make “splines” For example, we can get:
Positional (C0) Continuity:
DerivativeQ(C(10) )Continuity: = Qn −1 (1) , Qn (1) = Qn +1 ( 0 ) n
Qn ( 0) = Qn −1 (1) , Qn (1) = Qn +1 ( 0 ) Q: How would you build an interactive system to ( 0) = Qn′ −1 (1) , Qn′ (1) = Qn′ +1 ( 0) Qn′conditions? satisfy these
Graphics Lab @ Korea University
Advantages of Splines
CGVR
Advantages of splines over higher-order Bezier curves:
Numerically more stable Easier to compute Fewer bumps and wiggles
Graphics Lab @ Korea University
Tangent (G1) Continuity
CGVR
Q: Suppose the tangents were in opposite directions but not of same magnitude – how does the curves appear?
Qn ( 0) = Qn −1 (1) , Qn (1) = Qn +1 ( 0 ) Qn′ ( 0) = k1Qn′ −1 (1) , Qn′ (1) = k 2 Qn′ +1 ( 0 )
This construction gives “tangent (G1) continuity” Q: How is G1 continuity different from C1?
Graphics Lab @ Korea University
Explanation
CGVR
Positional (C0) continuity
Qn+1(u)
Qn(u)
Derivative (C1) continuity
Qn+1(u)
Qn(u)
Tangent (G1) continuity
Qn+1(u)
Qn(u) Graphics Lab @ Korea University
Curvature (C2) Continuity
CGVR
Q: Suppose you want even higher degrees of continuity – e.g., not just slopes but curvatures – what additional geometric constraints are imposed? Qn ( 0 ) = Qn −1 (1) , Qn (1) = Qn +1 ( 0 )
Qn′ ( 0 ) = Qn′ −1 (1) , Qn′ (1) = Qn′ +1 ( 0 ) Qn′′ ( 0 ) = Qn′′−1 (1) , Qn′′ (1) = Qn′′+1 ( 0 ) We’ll begin by developing some more mathematics.....
Graphics Lab @ Korea University
Operator Calculus
CGVR
Let’s use a tool known as “operator calculus” Define the operator D by: DVi ≡ Vi +1 Rewriting our explicit formulation in this notation gives: n n n −i i
Q( u ) = ∑ u (1 − u ) Vi i =0 i n n n n n −i i n −i i = ∑ u (1 − u ) DiV0 = ∑ ( uD ) (1 − u ) Vi i =0 i i =0 i
Applying the binomial theorem gives:
Q( u ) = ( uD + (1 − u ) ) V0 n
Graphics Lab @ Korea University
Taking the Derivative
CGVR
One advantage of this form is that now we can take the derivative:
Q ′( u ) = n( uD + (1 − u ) )
What’s (D-1)V0? Plugging in and expanding:
n −1
( D − 1)V0
n − 1 i n −1− i u (1 − u ) Q ′( u ) = n ∑ Di (V1 − V0 ) i =0 i This gives us a general expression for the derivative n −1
Q’(u)
Graphics Lab @ Korea University
Specializing to n=3
What’s the derivative Q’(u) for a cubic Bezier curve?
Q ′( u ) = 3( uD + (1 − u ) )
2
Note that:
CGVR
(
)
When u=0: Q’(u) = 3(V1-V0) When u=1: Q’(u) = 3(V3-V2)
Geometric interpretation: Q’(0)
Q′( 0) = 3( D − 1)V0 D − 1 V0 ′ 2 ( ) ( D − 1)V0 Q 1 = 3 D
V1
V0 W0 V2
So for C continuity, we need to set: 1
3(V3 − V2 ) = 3(W1 − W0 )
Q’(1) W1
V3
W2 W3 Graphics Lab @ Korea University
Taking the Second Derivative
CGVR
Taking the derivative once again yields: n−2 2 ′ ′ Q ( u ) = n( n − 1) ( uD + (1 − u ) ) ( D − 1) V0
What does (D-1)2 do?
Graphics Lab @ Korea University
Second-Order Continuity
CGVR
So the conditions for second-order continuity (V3 − V2 ) = (W1 − W0 ) are:
(V3 − V2 ) − (V2 − V1 ) = (W2 − W1 ) − (W1 − W0 )
Putting these together gives: W0 = V3 W1 = (V3 − V2 ) + W0 = 2V3 − V2
W2 = 2(V3 − V2 ) − (V2 − V1 ) + W1 = V1 − 4V2 + 4V3
Geometric interpretation V0 Q’(0)
V1
Q’’(0) Q’’(1)
V2
V3
Q’(1) Graphics Lab @ Korea University
C3 Continuity Q ′′′( u ) = n( n − 1)( n − 2) ( uD + (1 − u ) )
V0 V1
CGVR n −3
( D − 1) 3V0
V3 V2
Graphics Lab @ Korea University
C3 Continuity
CGVR
Q ′′′( u ) = n( n − 1)( n − 2) ( uD + (1 − u ) )
n −3
( D − 1) 3V0
W0 = V3 W1 V0 V1
V3
W2 W0
W3
V2
Graphics Lab @ Korea University
C3 Continuity
CGVR
Q ′′′( u ) = n( n − 1)( n − 2) ( uD + (1 − u ) )
n −3
( D − 1) 3V0
W0 = V3 W1 V0 V1
V3
W0
W1 = 2V3 − V2
W2 W3
V2
Graphics Lab @ Korea University
C3 Continuity
CGVR
Q ′′′( u ) = n( n − 1)( n − 2) ( uD + (1 − u ) ) W2 W1 V0 V1
V3
W0
n −3
( D − 1) 3V0
W0 = V3 W1 = 2V3 − V2 W3W2
= V1 − 4V2 + 4V3
V2
Graphics Lab @ Korea University
C3 Continuity
CGVR
Q ′′′( u ) = n( n − 1)( n − 2) ( uD + (1 − u ) ) W2
W3
W1 V0 V1
V3 V2
W0
n −3
( D − 1) 3V0
W0 = V3 W1 = 2V3 − V2
W2 = V1 − 4V2 + 4V3 W3 = 8V3 − 12V2 + 6V1 − V0
Graphics Lab @ Korea University
C3 Continuity
CGVR
Q ′′′( u ) = n( n − 1)( n − 2) ( uD + (1 − u ) ) W2
W3
W1 V0 V1
V3 V2
W0
n −3
( D − 1) 3V0
W0 = V3 W1 = 2V3 − V2
W2 = V1 − 4V2 + 4V3 W3 = 8V3 − 12V2 + 6V1 − V0
Summary of continuity conditions
C0 straightforward, but generally not enough C3 is too constrained (with cubics) Graphics Lab @ Korea University
Creating Continuous Splines
CGVR
We’ll look at three ways to specify splines with C1 and C2 continuity
C2 interpolating splines B-splines Catmull-Rom splines
Graphics Lab @ Korea University
C2 Interpolating Splines
CGVR
The control points specified by the user, called “joints”, joint are interpolated by the spline For each of x and y, we needed to specify 3 conditions for each cubic Bezier segment. So if there are m segments, we’ll need 3m-1 conditions Q: How many these constraints are determined by each joint? Graphics Lab @ Korea University
In-Depth Analysis
CGVR
At each interior joint j, we have: Last curve ends at j Next curve begins at j Tangents of two curves at j are equal Curvature of two curves at j are equal The m segments give: m-1 interior joints 3 conditions The 2 end joints give 2 further constraints: First curve begins at first joint Last curve ends at last joint Gives 3m-1 constraints altogether
Graphics Lab @ Korea University
End Conditions
CGVR
The analysis shows that specifying m+1 joints for m segments leaves 2 extra degree of freedom These 2 extra constraints can be specified in a variety of ways:
An interactive system
“Natural” cubic splines
Constraints specified as user inputs Second derivatives at endpoints defined to be 0
Maximal continuity
Require C3 continuity between first and last pairs of curves
Graphics Lab @ Korea University
C2 Interpolating Splines
CGVR
Problem: Describe an interactive system for specifying C2 interpolating splines Solution: 1. Let user specify first four Bezier control points 2. This constraints next 2 control points – draw these in. 3. User then picks 1 more 4. Repeat steps 2-3.
Graphics Lab @ Korea University
Global vs. Local Control
These C2 interpolating splines yield only “global control” – moving any one joint (or control point) changes the entire curve! Global control is problematic:
CGVR
Makes splines difficult to design Makes incremental display inefficient
There’s a fix, but nothing comes for free. Two choices:
B-splines
Keep C2 continuity Give up interpolation
Catmull-Rom Splines
Keep interpolation Give up C2 continuity – provides C1 only
Graphics Lab @ Korea University
B-Splines
Previous construction (C2 interpolating splines):
Choose joints, constrained by the “A-frames”
New construction (B-splines):
CGVR
Choose points on A-frames Let these determine the rest of Bezier control points and joints
The B-splines I’ll describe are known more precisely as “uniform B-splines”
Graphics Lab @ Korea University
Explanation
CGVR
C2 interpolating spline V0
V2
V1
B-splines
B2
B1 V1 V0 B0
V2
V3 B3 Graphics Lab @ Korea University
B-Spline Construction
CGVR
P( u ) = ∑ pk Bk , d ( u ) , u min ≤ u ≤ u max , 2 ≤ d ≤ n + 1 n
k =0
n+1 control points polynomials of degree d1 1, if u k ≤ u ≤ u k +1 Bk ,1 ( u ) = 0, otherwise u − uk uk +d − u Bk , d ( u ) = Bk , d −1 ( u ) + Bk +1, d −1 ( u ) u k + d −1 − u k u k + d − u k +1
Graphics Lab @ Korea University
B-Spline Construction
CGVR
P( u ) = ∑ pk Bk , d ( u ) , u min ≤ u ≤ u max , 2 ≤ d ≤ n + 1 n
k =0
n+1 control points polynomials of degree d1 1, if u k ≤ u ≤ u k +1 Bk ,1 ( u ) = 0, otherwise u − uk uk +d − u Bk , d ( u ) = Bk , d −1 ( u ) + Bk +1, d −1 ( u ) u k + d −1 − u k u k + d − u k +1
The points specified by the user in this construction are called “deBoor points” Graphics Lab @ Korea University
B-Spline Properties
CGVR
Here are some properties of B-splines:
C2 continuity
Approximating
Locality
Does not interpolate deBoor points Each segment determined by 4 deBoor points Each deBoor point determine 4 segments
Convex hull
Curves lies inside convex hull of deBoor points
Graphics Lab @ Korea University
Algebraic Construction of B-Splines
CGVR
P( u ) = ∑ Bk Fk ,3 ( u ) 3
k =0
= B0 F0,3 ( u ) + B1 F1,3 ( u ) + B2 F2,3 ( u ) + B3 F3,3 ( u )
(
)
1 1 2 3 F0,3 ( u ) = (1 − u ) , F1,3 ( u ) = 3u − 6u 2 + 4 , 6 6 1 1 3 3 2 F2,3 ( u ) = − 3u + 3u + 3u + 1 , F3,3 ( u ) = u 6 6
(
)
V1 = (1 - 1/3)B1 + 1/3 B2 V2 = (1- 2/3)B1 + 2/3 B2 V0 = ½ [(1- 2/3)B0 + 2/3 B1] + ½ [(1 - 1/3)B1 + 1/3 B2] = 1/6 B0 + 2/3 B1 + 1/6 B2 V3 = 1/6 B1 + 2/3 B2 + 1/6 B3 Graphics Lab @ Korea University
Algebraic Construction of B-Splines (cont.)
CGVR
Once again, this construction can be expressed in terms of a matrix:
V0 1 4 V 0 4 1 = 1 V2 6 0 2 0 1 V3
1 2 4 4
0 B0 B 0 1 0 B2 1 B3
Graphics Lab @ Korea University
Drawing B-Splines
CGVR
Drawing B-splines is therefore quite simple Procedure Draw-B-Spline ({B0, …, Bn}) for i=0 to n-3 do Convert Bi, …, Bi+3 into a Bezier control polygon V0, …, V3 Display({V0, …, Vn}) Display end for end procedure
Graphics Lab @ Korea University
Multiple Vertices
CGVR
Q: What happens if you put more than one control point in the same place?
Some possibilities:
Triple vertex Double vertex Collinear vertices
Graphics Lab @ Korea University
End Conditions
CGVR
You can also use multiple vertices at the endpoints
Double endpoints
Triple endpoints
Curve tangent to line between first distinct points Curve interpolates endpoint Start out with a line segment
Phantom vertices
Gives interpolation without line segment at ends
Graphics Lab @ Korea University
Catmull-Rom Splines
The Catmull-Rom splines
1. Last curve end at j 2. Next curve begins at j 3. Tangents of two curves at j are equal 4. Curvature of two curves at j are equal
If we…
Give up C2 continuity Keep interpolation
For the derivation, let’s go back to the interpolation algorithm. We had a conditions at each joint j:
CGVR
Eliminate condition 4 Make condition 3 depend only on local control points
… then we can have local control!
Graphics Lab @ Korea University
Derivation of Catmull-Rom Splines
CGVR
Idea: (same as B-splines)
Start with joints to interpolate Build a cubic Bezier curve between successive points
B0
B3 B2 =V3
B1 =V0
The endpoints of the cubic Bezier are obvious:
V0 = B1
V3 = B2 Q: What should we do for the other two points?
Graphics Lab @ Korea University
Derivation of Catmull-Rom (cont.)
A: Catmull & Rom use half the magnitude of the vector between adjacent control points: B0
B3 B1 =V0
CGVR
B2 =V3
Many other choices work – for example, using an arbitrary constant t times this vector gives a “tension” control
Graphics Lab @ Korea University
Matrix Formulation
The Catmull-Rom splines also admit a matrix formulation:
V0 0 V − 1 1 = 1 V2 6 0 0 V3
CGVR
6 6 1 0
0 0 B0 B 1 0 1 6 − 1 B2 6 0 B3
Exercise: Derive this matrix
Graphics Lab @ Korea University
Properties
CGVR
Here are some properties of Catmull-Rom splines:
C1 continuity Interpolating Locality No convex hull property
Graphics Lab @ Korea University