The following describes the mathematics for the so called Bézier curve. It is attributed and named after a French engineer, Pierre Bézier, who used them for the body design of the Renault car in the 1970's. They have since obtained dominance in the typesetting industry and in particular with the Adobe Postscript and font products.
Consider N+1 control points pk (k=0 to N) in 3 space. The Bézier parametric curve function is of the form

B(u) is a continuous function in 3 space defining the curve with N discrete control points Pk. u=0 at the first control point (k=0) and u=1 at the last control point (k=N).

Notes:
The curve in general does not pass through any of the control points except the first and last. From the formula B(0) = P0 and B(1) = PN.
The curve is always contained within the convex hull of the control points, it never oscillates wildly away from the control points.
If there is only one control point P0, ie: N=0 then B(u) = P0 for all u.
If there are only two control points
P0 and P1, ie: N=1 then the formula
reduces to a line segment between the two control points.
the term
is called a blending function since it blends the control points to form the Bézier curve.
The blending function is always a polynomial one degree less than the number of control points. Thus 3 control points results in a parabola, 4 control points a cubic curve etc.
Closed curves can be generated by making the last
control point the same as the first control point. First order
continuity can be achieved by ensuring the tangent between the
first two points and the last two points are the same.
Adding multiple control points at a single position
in space will add more
weight to that point "pulling" the Bézier curve towards it.

As the number of control points increases it is necessary to have higher
order polynomials and possibly higher factorials. It is common therefore to
piece together small sections of Bézier
curves to form a longer curve. This
also helps control local conditions, normally changing the position of one
control point will affect the whole curve. Of course since the curve starts and
ends at the first and last control point it is easy to physically match the
sections. It is also possible to match the first derivative since the tangent
at the ends is along the line between the two points at the end.
Second order continuity is generally not possible.

Except for the redundant cases of 2 control points (straight line), it is generally not possible to derive a Bézier curve that is parallel to another Bézier curve.
A circle cannot be exactly represented with a Bézier curve.
It isn't possible to create a Bézier curve that is parallel to another, except in the trivial cases of coincident parallel curves or straight line Bézier curves.
Special case, 3 control points
Special case, 4 control points
Bézier curves have wide applications because they are easy to compute and very stable. There are similar formulations which are also called Bézier curves which behave differently, in particular it is possible to create a similar curve except that it passes through the control points. See also Spline curves.
ExamplesThe pink lines show the control point polygon, the grey lines the Bézier curve.
|
The degree of the curve is one less than the number of control points, so it is a quadratic for 3 control points. It will always be symmetric for a symmetric control point arrangement. |
|
The curve always passes through the end points and is tangent to the line between the last two and first two control points. This permits ready piecing of multiple Bézier curves together with first order continuity. |
|
The curve always lies within the convex hull of the control points. Thus the curve is always "well behaved" and does not oscillating erratically. |
|
Closed curves are generated by specifying the first point the same as the last point. If the tangents at the first and last points match then the curve will be closed with first order continuity.. In addition, the curve may be pulled towards a control point by specifying it multiple times. |
/*
Three control point Bezier interpolation
mu ranges from 0 to 1, start to end of the curve
*/
XYZ Bezier3(XYZ p1,XYZ p2,XYZ p3,double mu)
{
double mum1,mum12,mu2;
XYZ p;
mu2 = mu * mu;
mum1 = 1 - mu;
mum12 = mum1 * mum1;
p.x = p1.x * mum12 + 2 * p2.x * mum1 * mu + p3.x * mu2;
p.y = p1.y * mum12 + 2 * p2.y * mum1 * mu + p3.y * mu2;
p.z = p1.z * mum12 + 2 * p2.z * mum1 * mu + p3.z * mu2;
return(p);
}
/*
Four control point Bezier interpolation
mu ranges from 0 to 1, start to end of curve
*/
XYZ Bezier4(XYZ p1,XYZ p2,XYZ p3,XYZ p4,double mu)
{
double mum1,mum13,mu3;
XYZ p;
mum1 = 1 - mu;
mum13 = mum1 * mum1 * mum1;
mu3 = mu * mu * mu;
p.x = mum13*p1.x + 3*mu*mum1*mum1*p2.x + 3*mu*mu*mum1*p3.x + mu3*p4.x;
p.y = mum13*p1.y + 3*mu*mum1*mum1*p2.y + 3*mu*mu*mum1*p3.y + mu3*p4.y;
p.z = mum13*p1.z + 3*mu*mum1*mum1*p2.z + 3*mu*mu*mum1*p3.z + mu3*p4.z;
return(p);
}
/*
General Bezier curve
Number of control points is n+1
0 <= mu < 1 IMPORTANT, the last point is not computed
*/
XYZ Bezier(XYZ *p,int n,double mu)
{
int k,kn,nn,nkn;
double blend,muk,munk;
XYZ b = {0.0,0.0,0.0};
muk = 1;
munk = pow(1-mu,(double)n);
for (k=0;k<=n;k++) {
nn = n;
kn = k;
nkn = n - k;
blend = muk * munk;
muk *= mu;
munk /= (1-mu);
while (nn >= 1) {
blend *= nn;
nn--;
if (kn > 1) {
blend /= (double)kn;
kn--;
}
if (nkn > 1) {
blend /= (double)nkn;
nkn--;
}
}
b.x += p[k].x * blend;
b.y += p[k].y * blend;
b.z += p[k].z * blend;
}
return(b);
}