Convex hull - kuas.edu.tw

Computer Graphics(電腦繪圖學)
Convex hull (凸殻) property

The convex hull of a set of points S in n dimensions is the intersection of all
convex sets containing S. For N points P1, ..., PN, 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 fi(u)

 f1(u) + ...
1 for u in [0,1].
+ fn(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
Bernstein polynomials have 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) = i 0 Bi ,n (u ) Pi
n
n i

where Bi ,n (u ) 
u (1 u ) n i is called Bernstein basis function, it satisfies
i 



n
i 0
Bi ,n (u ) [(1 u ) u ]n 1 . ※二項式係數: n! / [i!(n-i)!]
C. F. Chang, 2003
Computer Graphics(電腦繪圖學)
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.
T1
P1
P4, P’1
P’4
T’4
T4, T’1
In terms of the above figure, this means P1'=P4, T1'=k T4.
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
G0: curves are joined
G1: the first derivatives of curves are proportional at the join point
The curve tangents of the curves thus have the same direction, but not
necessarily the same magnitude.
2

 G : the first and second derivatives are proportional at join point




Parametric Continuity
C0: curves are joined
C1: first derivatives are equal
C2: first and second derivatives are equal
If u is taken to be time, this implies that the acceleration is continuous.
n
th

 C : n derivatives are equal






C. F. Chang, 2003
Computer Graphics(電腦繪圖學)
As their names imply, geometric continuity requires the geometry to be continuous,
while parametric continuity requires that the underlying parameterization be
continuous as well.
Parametric continuity of order n implies geometric continuity of order n, but not
vice-versa.
Summary of Bezier and Hermite Curves






offer local control
offer C1 continuity
interpolates (some) control points
Splines
splines are cubic curves which maintain C2 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 Bézier 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.
C. F. Chang, 2003
Computer Graphics(電腦繪圖學)
○Knot Control point
Each curve segment Q is determined by four control points, as follows:
Q1
Q2
P0 P1 P2 P3 P4 P5 P6
Q3
Q4
B-spline curves are defined by a basis matrix, just like the other types of cubic curves.
1 3 3


1 3 6 3
MBspline = 
3 0
3
6

4
1
1
1
0

0

0
where the geometry vector consists of four consecutive control points. It is easy to
show that B-spline curves are C2 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, P0, …
Pm, and m-2 segments, Q3, … Qm.

Qi (u ) (u ui ) 3
(u ui ) 2
(u ui )1
Pi 3 


Pi 2 

, ui u < ui+1
1 M Bspline

Pi 1 
 
Pi 

The entire curve is generated by applying this equation for 3 i m. If expanding the
equation, and replacing u-ui with t, we have
Qi(t)=[(1-t)3/6]Pi-3 +[(3t3-6t2+4)/6]Pi-2 +[(-3t3+3t2+3t+1)/6]Pi-1 +[t3/6]Pi, 0 t < 1
C. F. Chang, 2003
Computer Graphics(電腦繪圖學)
The basis functions for the B-spline are as follows:


1
0.8
f1(t)
0.6
f2(t)
0.4
f3(t)
f4(t)
0.2
0.9
0
0.7
f4(t)
0
0.00017
0.00133
0.0045
0.01067
0.02083
0.036
0.05717
0.08533
0.1215
0.16667
0.
5
f3(t)
0.166667
0.221167
0.282667
0.348167
0.414667
0.479167
0.538667
0.590167
0.630667
0.657167
0.666667
0.
3
f2(t)
0.666667
0.657167
0.630667
0.590167
0.538667
0.479167
0.414667
0.348167
0.282667
0.221167
0.166667
0.
1
f1(t)
0.1666667
0.1215
0.0853333
0.0571667
0.036
0.0208333
0.0106667
0.0045
0.0013333
0.0001667
0
t
t
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
A B-spline is Uniform if its internal knots are equally spaced
A B-spline with no internal knots is a Bézier curve
Multiple knots
Control vertices can be repeated in order to allow for reduced geometric continuity at
the join points.
Multiplicity
1
G2 continuous
2
G1 continuous
3
G0 continuous, interpolates point
Double knot at D
D
Single knot at D
B
E
G
A
C
F
NURBS: Nonuniform Rational B-splines
One of the disadvantages of the curves discussed to date is that they cannot be used to
create common conic shapes such as circles, ellipses, parabolas, etc. This can be done
using rational cubic curves, however.
C. F. Chang, 2003
Computer Graphics(電腦繪圖學)
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;
}
}
C. F. Chang, 2003
Computer Graphics(電腦繪圖學)
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;
}
C. F. Chang, 2003