6 2 Parametric Curves-2
6 2 Parametric Curves-2
C. F. Chang, 2003
Convex hull () property
The convexhull of a set of points S in n dimensions is the intersection of all
convex sets containing S. For N points P
1
, ..., P
N
, the convex hull C is then given
by the expression
The convex hull property ensures that a parametric curve will never pass
outside of the convex hull formed by the four control vertices. As such, it lends
a measure of predictability to the curve.
The Bezier basis functions satisfy the conditions necessary for the convex hull
property, namely:
- 0 s f
i
(u) s 1 for u in [0,1].
- f
1
(u) + ... + f
n
(u) = 1
Bezier Curves of degree n
It is not per chance that the basis functions for Bezier curves have the convex hull
property. How might one then go about designing a set of basis functions that sum to
one and ensure that each individual basis function remain in the range [0,1]? The
Bernsteinpolynomialshave exactly the required properties.
Using the Bernstein polynomials, we can construct a Bezier curve of arbitrary degree.
For curves of higher degree than the cubic Bezier curve, we'll need more than four
control points. The general Bezier curve of degree n is given by
P(u) =
=
n
i
i n i
P u B
0
,
) (
where
i n i
n i
u u
i
n
u B
|
|
.
|
\
|
= ) 1 ( ) (
,
is called Bernstein basis function, it satisfies
=
= + =
n
i
n
n i
u u u B
0
,
1 ] ) 1 [( ) ( . : n! / [i!(n-i)!]
Computer Graphics()
C. F. Chang, 2003
That means the basis functions are equivalent to the terms arising from the expansion
of
[u + (1-u) ]
n
using the binomial expansion theorem(). It is also obvious from this why
the sum of all the terms is equal to one.
Piecewise Hermite and Bezier Curves
Hermite curve segments can be connected in a continuous fashion by ensuring that the
end-point of one curve is the same as the starting point of another, as well as ensuring
that the tangent vectors for this point have the same direction.
T
1
P
1
P
4,
P
1
P
4
T
4
T
4,
T
1
In terms of the above figure, this means P
1
'=P
4
, T
1
'=k T
4
.
For a Bezier curve, the conditions are that the last two points of one curve and the first
two points of the second curve are aligned.
Geometric and Parametric Continuity
Geometric Continuity
- G
0
: curves are joined
- G
1
: the first derivatives of curves are proportional at thejoinpoint
The curve tangents of the curves thus have the same direction, but not
necessarily the same magnitude.
- G
2
: the first and second derivatives are proportional at joinpoint
Parametric Continuity
- C
0
: curves are joined
- C
1
: first derivatives are equal
- C
2
: first and second derivatives are equal
If u is taken to be time, this implies that the acceleration is continuous.
- C
n
: n
th
derivatives are equal
Computer Graphics()
C. F. Chang, 2003
As their names imply, geometric continuity requires the geometry to be continuous,
while parametric continuity requires that the underlying parameterization be
continuous as well.
Parametriccontinuityof order nimpliesgeometriccontinuityof order n, but not
vice-versa.
Summary of Bezier and Hermite Curves
- offer local control
- offer C
1
continuity
- interpolates (some) control points
Splines
- splines are cubic curves which maintain C
2
continuity.
- natural spline
o interpolates all of its control points.
o equivalent to a thin strip of metal forced to pass through control points
o no local control
- B-spline (A generation of Bzier curve)
o local control
o does not interpolate control points
The following is an example of a four-segment B-spline curve. The points that
indicate the ends of the individual curve segments and thus the join points are known
as the knots.
Computer Graphics()
C. F. Chang, 2003
Knot - Control point
Each curve segment Q is determined by four control points, as follows:
P
0
P
1
P
2
P
3
P
4
P
5
P
6
Q
1
Q
2
Q
3
Q
4
B-spline curves are defined by a basis matrix, just like the other types of cubic curves.
M
Bspline
=
(
(
(
(
0 1 4 1
0 3 0 3
0 3 6 3
1 3 3 1
6
1
where the geometry vector consists of four consecutive control points. It is easy to
show that B-spline curves are C
2
continuous and that they satisfy the convex-hull
property.
In the following is the general form of a B-spline having m+1 control points, P
0
,
P
m
, and m-2 segments, Q
3
, Q
m
.
| |
(
(
(
(
i
i
i
i
Bspline i i i i
P
P
P
P
u u u u u u u Q
1
2
3
1 2 3
1 ) ( ) ( ) ( ) ( M , u
i
s u < u
i+1
The entire curve is generated by applying this equation for 3 s i s m. If expanding the
equation, and replacing u-u
i
with t, we have
Q
i
(t)=[(1-t)
3
/6]P
i-3
+[(3t
3
-6t
2
+4)/6]P
i-2
+[(-3t
3
+3t
2
+3t+1)/6]P
i-1
+[t
3
/6]P
i
, 0 s t < 1
Computer Graphics()
C. F. Chang, 2003
The basis functions for the B-spline are as follows:
t f1(t) f2(t) f3(t) f4(t)
0 0.1666667 0.666667 0.166667 0
0.1 0.1215 0.657167 0.221167 0.00017
0.2 0.0853333 0.630667 0.282667 0.00133
0.3 0.0571667 0.590167 0.348167 0.0045
0.4 0.036 0.538667 0.414667 0.01067
0.5 0.0208333 0.479167 0.479167 0.02083
0.6 0.0106667 0.414667 0.538667 0.036
0.7 0.0045 0.348167 0.590167 0.05717
0.8 0.0013333 0.282667 0.630667 0.08533
0.9 0.0001667 0.221167 0.657167 0.1215
1 0 0.166667 0.666667 0.16667
0
0.2
0.4
0.6
0.8
1
t
0
.
1
0
.
3
0
.
5
0
.
7
0
.
9
f1(t)
f2(t)
f3(t)
f4(t)
A B-spline is Uniform if its internal knots are equally spaced
A B-spline with no internal knots is a Bzier curve
Multiple knots
Control vertices can be repeated in order to allow for reduced geometric continuity at
the join points.
Multiplicity
1 G
2
continuous
2 G
1
continuous
3 G
0
continuous, interpolates point
A
G
D
E
C
F
B
Double knot at D
Single knot at D
NURBS: Nonuniform Rational B-splines
One of the disadvantages of the curves discussed to date is that they cannot be used to
create common conicshapessuch as circles, ellipses, parabolas, etc. This can be done
using rational cubic curves, however.
Computer Graphics()
C. F. Chang, 2003
General rational cubic curve segments are ratios of polynomials:
x(u) = X(u)/W(u)
y(u) = Y(u)/W(u)
z(u) = Z(u)/W(u)
where X(u), Y(u), Z(u), and W(u) are cubic polynomial curves whose control points
are defined in homogeneous coordinates. Defining curves as rational polynomials in
this manner allows for simple exact representations of conic sections such as circles,
as well as curves that are invariant under perspective projection.
SAMPLE CODE FOR DRAWING BEZIER CURVE
#include <math.h>
void computeCoefficients (int n, int * c)
{
int k, i;
for (k=0; k<=n; k++) {
/* Compute n!/(k!(n-k)!) */
c[k] = 1;
for (i=n; i>=k+1; i--)
c[k] *= i;
for (i=n-k; i>=2; i--)
c[k] /= i;
}
}
void computePoint (float u, Point3 * pt, int nControls, Point3 * controls, int * c)
{
int k, n = nControls - 1;
float blend;
pt->x = 0.0; pt->y = 0.0; pt->z = 0.0;
/* Add in influence of each control point */
for (k=0; k<nControls; k++) {
blend = c[k] * powf (u,k) * powf (1-u,n-k);
pt->x += controls[k].x * blend;
pt->y += controls[k].y * blend;
pt->z += controls[k].z * blend;
}
}
Computer Graphics()
C. F. Chang, 2003
void bezier (Point3 * controls, int nControls, int m, Point3 * curve)
{
/* Allocate space for the coefficients */
int * c = (int *) malloc (nControls * sizeof (int));
int i;
computeCoefficients (nControls-1, c);
for (i=0; i<=m; i++)
computePoint (i / (float) m, &curve[i], nControls, controls, c);
free (c);
}
#define N_CONTROLS 4
#define N_PTS 128
void main (int argc, char ** argv)
{
int i;
float pt[3];
Point3 pts[] = { 50, 50, 0, 150, 150, 0, 250, 40, 0, 300, 200, 0 };
Point3 curvePts[N_PTS+1];
bezier (pts, N_CONTROLS, N_PTS, curvePts);
/* Draw the lines */
glBegin( )
for (i=0; i<N_PTS; i++) {
pt[0] = curvePts[i].x;
pt[1] = curvePts[i].y;
pt[2] = curvePts[i].z;
glVertex ( );
}
glEnd;
}