2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss types of algebraic curves and surfaces...
-
Upload
angela-hodge -
Category
Documents
-
view
215 -
download
1
Transcript of 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss types of algebraic curves and surfaces...
2COEN 290 - Computer Graphics I
Evening’s Goals
Discuss types of algebraic curves and surfaces
Develop an understanding of curve basis and blending functions
Introduce Non-Uniform Rational B-Splines• also known as NURBS
3COEN 290 - Computer Graphics I
Problem #1
We want to create a curve (surface) which passes through as set of data points
4COEN 290 - Computer Graphics I
Problem #2
We want to represent a curve (surface) for modeling objects• compact form• easy to share and manipulate• doesn’t necessarily pass through points
5COEN 290 - Computer Graphics I
Types of Algebraic Curves (Surfaces)
Interpolating• curve passes through points• useful of scientific visualization and data
analysis Approximating
• curve’s shape controlled by points• useful for geometric modeling
6COEN 290 - Computer Graphics I
Representing Curves
We’ll generally use parametric cubic polynomials• easy to work with• nice continuity properties
3
0
33
2210)(
i
iiuc
ucucuccup
7COEN 290 - Computer Graphics I
Parametric Equations
Compute values based on a parameter• parameter generally defined over a limited
space• for our examples, let
For example
1,0u
)2sin()2cos()( uuuf
8COEN 290 - Computer Graphics I
What’s Required for Determining a Curve
Enough data points to determine coefficients• four points required for a cubic curve
For a smooth curve, want to match• continuity• derivatives
Good news is that this has all been figured out
9COEN 290 - Computer Graphics I
Geometry Matrices
We can identify curve types by their geometry matrix• another 4x4 matrix
Used to define the polynomial coefficients for a curves blending functions
10
COEN 290 - Computer Graphics I
Interpolating Curves
We can use the interpolating geometry matrix to determine coefficients
Given four points in n-dimensional space , compute
3
2
1
0
3
2
1
0
5.45.135.135.4
5.4185.229
15.495.5
0001
p
p
p
p
c
c
c
c
ip
ic
11
COEN 290 - Computer Graphics I
Recasting the Matrix Form as Polynomials
We can rewrite things a little
cuup
)( 321 uuuu
pMc g
pub
pMuup g
)(
)(
12
COEN 290 - Computer Graphics I
Blending Functions
Computing static coefficients is alright, but we’d like a more general approach
Recast the problem to finding simple polynomials which can be used as coefficients
3
0
)()(i
ii pubup
13
COEN 290 - Computer Graphics I
Blending Functions ( cont. )
Here are the blending functions for the interpolation curve
323
322
321
320
5.45.41)(
5.13185.4)(
5.135.229)(
5.495.51)(
uuuub
uuuub
uuuub
uuuub
14
COEN 290 - Computer Graphics I
Blending Functions ( cont. )
-0.5
-0.25
0
0.25
0.5
0.75
1
1.250.00
0.09
0.18
0.27
0.36
0.45
0.54
0.63
0.72
0.81
0.90
0.99
b0(u)
b1(u)
b2(u)
b3(u)
Blending Functions for the Interpolation case
15
COEN 290 - Computer Graphics I
That’s nice … but
Interpolating curves have their problems• need both data values and coefficients to share• hard to control curvature (derivatives)
Like a less data dependent solution
16
COEN 290 - Computer Graphics I
Approximating Curves
Control the shape of the curve by positioning control points
Multiples types available• Bezier• B-Splines• NURBS (Non-Uniform Rational B-Splines)
Also available for surfaces
17
COEN 290 - Computer Graphics I
Bezier Curves
Developed by a car designer at Renault Advantages
• curve contained to convex hull• easy to manipulate• easy to render
Disadvantages• bad continuity at endpoints
– tough to join multiple Bezier splines
18
COEN 290 - Computer Graphics I
Bezier Curves ( cont. )
Bezier geometry matrix
1331
0363
0033
0001
gM
19
COEN 290 - Computer Graphics I
Bernstein Polynomials
Bezier blending functions are a special set of called the Bernstein Polynomials• basis of OpenGL’s curve evaluators
knknk uu
k
nub
)1()(
)!(!
!
knk
n
k
n
20
COEN 290 - Computer Graphics I
Bezier Blending Functions
0
0.25
0.5
0.75
1
1.25
0.00
0.09
0.18
0.27
0.36
0.45
0.54
0.63
0.72
0.81
0.90
0.99
b0(u)
b1(u)
b2(u)
b3(u)
21
COEN 290 - Computer Graphics I
Cubic B-Splines
B-Splines provide the one thing which Bezier curves don’t -- continuity of derivatives
However, they’re more difficult to model with• curve doesn’t intersect any of the control
vertices
22
COEN 290 - Computer Graphics I
Curve Continuity
Like all the splines we’ve seen, the curve is only defined over four control points
How do we match the curve’s derivatives?
2ip
1ipip
1ip
2ip
23
COEN 290 - Computer Graphics I
Cubic B-Splines ( cont. )
B-Spline Geometry Matrix
1331
0363
0303
0141
61
gM
24
COEN 290 - Computer Graphics I
B-Spline Blending Functions
-0
1/6
1/3
1/2
2/3
5/6
1
0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
b0(u)
b1(u)
b2(u)
b3(u)
25
COEN 290 - Computer Graphics I
B-Spline Blending Functions ( cont. )
Notice something about the blending functions
Additionally, note that
3
0
0.1)(i
i ub
)`1()0(
)1()0(
)1()0(
32
21
10
bb
bb
bb
26
COEN 290 - Computer Graphics I
Basis Functions
The blending functions for B-splines form a basis set.• The “B” in B-spline is for “basis”
The basis functions for B-splines comes from the following recursion relation
otherwise0
1)( 10 kk
k
uuuuB
kB
)()()( 11
1
11uBuBuB d
kuuuud
kuuuud
k kdk
dk
kdk
k
27
COEN 290 - Computer Graphics I
Rendering Curves - Method 1
Evaluate the polynomial explicitly
33
2210)( ucucuccup
float px( float u ) { float v = c[0].x; v += c[1].x * u; v += c[2].x * pow( u, 2 ); v += c[3].x * pow( u, 3 ); return v;}
28
COEN 290 - Computer Graphics I
Evaluating Polynomials
That’s about the worst way you can compute a polynomial• very inefficient
–pow( u, n );
This is better, but still not great
float px( float u ) { float v = c[0].x; v += c[1].x * u; v += c[2].x * u*u; v += c[3].x * u*u*u; return v;}
29
COEN 290 - Computer Graphics I
Horner’s Method
We do a lot more work than necessary• computing u2 and u3 is wasteful
uuu
uuuu
uuu
3
2
30
COEN 290 - Computer Graphics I
Horner’s Method ( cont. )
Rewrite the polynomial
uccucuc
ucucuccup
3210
33
2210)(
float px( float u ) { return c[0].x + u*(c[1].x + u*(c[2].x + u*c[3].x)); }
31
COEN 290 - Computer Graphics I
Rendering Curves - Method 1 ( cont. )
Even with Horner’s Method, this isn’t the best way to render• equal sized steps in parameter doesn’t
necessarily mean equal sized steps in world space
glBegin( GL_LINE_STRIP );for ( u = 0; u <= 1; u += du ) glVertex2f( px(u), py(u) );glEnd();
32
COEN 290 - Computer Graphics I
Rendering Curves - Method 2
Use subdivision and recursion to render curves better
Bezier curves subdivide easily
0p
1p 2p
3p
p
1021 ppp
33
COEN 290 - Computer Graphics I
Rendering Curves - Method 2
Three subdivision steps required
212
11102
10
3221
22121
11021
0
pppppp
ppppppppp
32108
1
1021
0
33 pppp
ppp
34
COEN 290 - Computer Graphics I
Rendering Curves - Method 2
void drawCurve( Point p[] ) { if ( length( p ) < MAX_LENGTH ) draw( p ); Point p01 = 0.5*( p[0] + p[1] ); Point p12 = 0.5*( p[1] + p[2] ); Point p23 = 0.5*( p[2] + p[3] ); Point p012 = 0.5*( p01 + p12 ); Point p123 = 0.5*( p12 + p13 ); Point m = 0.5*( p012 + p123 ); drawCurve( p[0], p01, p012, m ); drawCurve( m, p123, p23, p[3] );}