Professional Documents
Culture Documents
4
Background: Interpolation
Given a set of n points (xi, yi) we may be able to define a
polynomial that goes through each point.
Solution: Lagrange Polynomial
Assumes no two points with the same x but different y
Thus cannot draw circle
6
Runge Phenomena
Interpolate at evenly spaced points
Difficult to get local control with high order polynomials
9
Functions
Natural parameterization
Moves with curve length
Sample Surface
Blending Functions
Linear Bezier Curve
In the expression, the terms p0 and p1 are vectors, and
their weighted sum is a vector
This is a powerful technique, and we will use it all night
Blending Functions
Piece these together
Piece together a curve that connects a set of points
p0
p2
p1
p3
p4
Piece these together
Piece together a curve that connects a set of points
p0
p2
p1
p3
p4
Piece these together
Create series of equations p2
p0
p1
p0 p3
p1 p4
p2
p3
p4
Blending Functions
Piece these together
Create series of equations p2
p0
p1
p0 p3
p1 p4
p2
Interpolate set of arbitrary points
p3
Easy and efficient to compute
p4
Smooth
Blending Functions
Local Control
Piece these together
Create series of equations p2
p0
p1
p0 p3
p1 p4
p2
T Interpolate set of arbitrary points
p3
T Easy and efficient to compute
p4
F Smooth – Nope - sharp "corners"
Blending Functions
T Local Control
Piece these together
Create series of equations p2
p0
p1
p0 p3
p1 p4
p2
Reasons
These allow C(1) and even C(2) continuity
Allow minimum-curvature interpolants to a set of points
Can define position and curvature at two ends
Cubic Polynomials are in the sweet spot:
Smooth, and easy to compute
Implemented with 4x4 matrices, just like rest of OpenGL
23
Bezier Animation
http://zonalandeducation.com/mmts/curveFitting/
bezierCurves/bca2/Bezier1Animation2.html
24
Note rate of movement
25
Bezier Curve
We will look at Bezier Curves in some detail tonight
There are different ways to think about them:
All paths lead to the same curves
De Castlejau Algorithm (recursive subdivision)
Bernstein Polynomials
Matrix Form
Cubic equations
All have their uses, and you will see all in practice
26
De Casteljau Algorithm
Compute points on the curve without evaluating polynomials
Can use the midpoints, so only need to shift right
27
De Casteljau's Method
Compute points on the curve without evaluating polynomials
Can use the midpoints, so only need to shift right
28
De Casteljau's Method
Gives simple recursive method to draw curve
29
Recursive Drawing Algorithm
31
De Casteljau
Derivation is similar
Find third level
Bezier Curve
There are different ways to think about them:
De Castlejau Algorithm (recursive subdivision)
Bernstein Polynomials
Matrix Form
Cubic equations
All have their uses, and you will see all in practice
35
Bernstein Polynomials
We write a Bezier as the weighted sum of control points
The control points are multiplied by Bernstein polynomials
Convex sum of polynomials with values in [0..1] that sum to 1
Each polynomial pulls curve towards it's control point
36
What does it mean?
We use these blending functions to decide the amount of
contribution from each control point.
Note that the terms add up to one
Why Polynomials?
Easy to evaluate
Continuous and differentiable everywhere
Must worry about continuity at join points including
continuity of derivatives
p(u)
q(u)
Thus the curve lies inside the convex hull of the control points
Convex Hull
40
Bezier Curve
All paths lead to the same point
De Castlejau Algorithm (recursive subdivision)
Bernstein Polynomials
Matrix Form
Cubic equations
All have their uses, and you will see all in practice
41
How did we pick blending functions?
What do we want from blending functions?
Active Blending Functions
Nice to have all non-negative terms
Functions should be smooth (rather than the pyramids)
Where did we get these blending functions?
Review: Blending function for line
We know p0 and p1. We want vectors a0 and a1 so that
Blending function for the line
We could solve this by hand: a0 = p0, etc.
But let's evolve a general method
Blending Functions
Blending functions for Bezier
Know p0, p1, p2, and p3, want vectors a0, a1, a2, and a3
so that our curve has the form
What do we know?
We know that f(t) interpolates p0 and p3 at t=0 and t=1
Constraint Matrix for Bezier
We also know that the slope at the ends is 3(p 1-p0)
Compute slope:
Evaluate at t=0 and t=1
Constraint Matrix for Bezier
Now we have a constraint matrix C: find it’s inverse B
Apply Constraint Matrix
Apply the vector [1 u u2 u3] to matrix B
Bezier Curve
All paths lead to the same point
De Castlejau Algorithm (recursive subdivision)
Bernstein Polynomials
Matrix Form
Cubic equations
All have their uses, and you will see all in practice
51
Derive the values ai
Another way to look at this:
NURBS
Nonuniform Rational B-Spline curves and surfaces
add a fourth variable w to x,y,z
Can interpret as weight to give more importance
to some control data
Can also interpret as moving to homogeneous
coordinate
Requires a perspective division
NURBS act correctly for perspective viewing
Quadrics are a special case of NURBS
53 E. Angel and D. Shreiner: Interactive Computer
Graphics 6E © Addison-Wesley 2012
NURBS
Non-Uniform Rational B-Splines
Note that Rational is usually a restriction
Rational numbers vs all real numbers.
Here it is an extension: Projective Geometry
Example: we wish to draw a unit circle
No exact match with Cubic Beziers – can get close
However, if we use projective space…
Quadratic Bezier
x
Degree Elevation
p0 p2
Use this technique to find a curve that interpolates
control points
Start by computing constraints: must hit
p0 at 0,
p1 at 1/3,
p2 at 2/3,
Interpolating Cubic
p1 p3
p0 p2
Use this technique to find a curve that interpolates
control points
Start by computing constraints: must hit
p0 at 0,
p1 at 1/3,
p2 at 2/3,
Interpolation Matrix
Solving for c we find the interpolation matrix
1 0 0 0
5. 5 9 4 .5 1
M I A 9 22.5 18 4.5
1
4 .5 13 . 5 13 .5 4 . 5
c=MIp
Note that MI does not depend on input data and
can be used for each segment in x, y, and z
64
Cubic Hermite Spline
Sometimes we want to avoid sharp corners
Can define the slope at the endpoints
Hermite Polynomials use a new blending functions
to define curve
p’(0) p’(1)
p(0) p(1)
Hermite Polynomial
Hermite Polynomial
Analysis
Bezier form has advantages over interpolating form,
derivatives need note be continuous at join points
Can we do better?
Go to higher order Bezier
More work
Derivative continuity still only approximate
Supported by OpenGL
Apply different conditions
Tricky without letting order increase
68 E. Angel and D. Shreiner: Interactive Computer
Graphics 6E © Addison-Wesley 2012
Splines
Approximate rather than interpolate (blue vs red curves)
(Image is of a traditional spline used in boat building)
69
B-Splines
Basis splines: use the data at p=[pi-2 pi-1 pi pi-1]T to define
curve only between pi-1 and pi
We can apply more continuity conditions to each segment
For cubics, we can have continuity of function, first and
second derivatives at join points - C(2)
Cost is 3 times as much work for curves
Add one new point each time rather than three
For surfaces, we do 9 times as much work
E. Angel and D. Shreiner: Interactive Computer
70 Graphics 6E © Addison-Wesley 2012
Cubic B-spline
p(u) = uTMSp = b(u)Tp
1 4 1 0
3 0 3 0
MS 3 6 3 0
1 3 3 1
p(u ) Bi (u ) pi
78
Bezier Curve
void drawCurve() {
int i;
GLfloat pts[4][3];
/* Copy the coordinates from balls to array */
for (i = 0; i < 4; i++) {
pts[i][0] = (GLfloat)cp[i]->x;
pts[i][1] = (GLfloat)wh - (GLfloat)cp[i]->y;
pts[i][2] = (GLfloat)0.0;
}
// Define the evaluator
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &pts[0][0]);
/* type, u_min, u_max, stride, num points, points */
glEnable(GL_MAP1_VERTEX_3);
setLineColor();
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
/* Evaluate the curve when u = i/30 */
glEvalCoord1f((GLfloat) i/ 30.0);
glEnd();
Teapot
bteapot.c
// vertices.h
GLfloat vertices[306][3]={{1.4 , 0.0 , 2.4}, {1.4 , -0.784 , 2.4},
{0.784 , -1.4 , 2.4}, {0.0 , -1.4 , 2.4}, {1.3375 , 0.0 , 2.53125},
{1.3375 , -0.749 , 2.53125}, {0.749 , -1.3375 , 2.53125}, {0.0 , -1.3375 ,
2.53125},
{1.4375 , 0.0 , 2.53125}, {1.4375 , -0.805 , 2.53125}, {0.805 , -1.4375 ,
2.53125},
...
// patches.h
int indices[32][4][4]={{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16},
{4, 17, 18, 19, 8, 20, 21, 22, 12, 23, 24, 25, 16, 26, 27, 28},
{19, 29, 30, 31, 22, 32, 33, 34, 25, 35, 36, 37, 28, 38, 39, 40},
...
bteapot.c
/* 32 patches each defined by 16 vertices, arranged in a 4 x 4 array */
/* NOTE: numbering scheme for teapot has vertices labeled from 1 to 306 */
/* remnent of the days of FORTRAN */
#include "patches.h"
void display(void)
{
int i, j, k;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glRotatef(-35.26, 1.0, 0.0, 0.0);
glRotatef(-45.0, 0.0, 1.0, 0.0);
85
Summary
We often wish to generate curves and surfaces
We would like
Interpolate (include) a set of arbitrary points
Easy and efficient to compute
Smooth
Local Control…
By splicing together pieces of curves, we can attain
many of these.
Modern hardware and language support these curves
86