Bezier Curves

A cubic Bezier curve is defined via the Bernstein polynomials of degree 3, given by  
                  (Subscript[B, 0])(x) = (x^3),  (Subscript[B, 1])(x) = 3(x^2)(1-x) ,  (Subscript[B, 2])(x) = 3((x(1-x))^2), (Subscript[B, 3])(x) = (1-((x))^3).      
Here is a plot of these polynomials:

Plot[{(1-t)^3, 3 t (1-t), 3t^2(1-t), t^3}, {t,0,1}]

A cubic Bezier curve is defined via the Bernstein polynomials of degree 3, given by  
                  (Subscript[B, 0])(x) = (x^3),  (Subscript[B, 1])(x) = 3(x^2)(1-x) ,  (Subscript[B, 2])(x) = 3((x(1-x))^2), (Subscript[B, 3])(x) = (1-((x))^3).
The curve has 4 control points: (Subscript[a, 0])=((Subscript[x, 0]), (Subscript[y, 0])), (Subscript[a, 1])=((Subscript[x, 1]), (Subscript[y, 1])), (Subscript[a, 2])=((Subscript[x, 2]), (Subscript[y, 2])), (Subscript[a, 3])=((Subscript[x, 3]), (Subscript[y, 3])), and it is given by the formula 
                   P(t)= (Subscript[a, 0]) (Subscript[B, 0])(t) + (Subscript[a, 1]) (Subscript[B, 1])(t) + (Subscript[a, 2]) (Subscript[B, 2])(t) + (Subscript[a, 3]) (Subscript[B, 3])(t),       t in [0,1].
Note that this is a parametric curve, since the control points has two components.

Bezier[XY0_,t_] := Block[{n,XY},XY = XY0;  
B[t]= XY[[1]](1-t)^3+XY[[2]] 3t(1-t)^2+XY[[3]] 3t^2(1-t)+XY[[4]]t^3 ;
Return[B[t]]; ];

Example 1.

XY = {{0.,1.},{1.,0.},{2.,0.2}, {3.,1.5}};
B[t_]=Bezier[XY,t];
BX[t_]=B[t][[1]];BY[t_]=B[t][[2]];

dots = ListPlot[XY,PlotStyle->{PointSize[0.02]},DisplayFunction->Identity];
gr = ParametricPlot[{BX[t],BY[t]},{t,0,1},DisplayFunction->Identity];
txt = StringForm["Bezier Curve and Control Points"];
Show[dots,gr,Graphics[Line[XY]], Axes -> False, AspectRatio -> 0.5,DisplayFunction->$DisplayFunction,PlotLabel->txt]

The cubic Bezier curve P(t) satisfies the following properties:   
                  P(0) = (Subscript[a, 0]),    P(1) =(Subscript[a, 3]),    P'(0) = 3 ( (Subscript[a, 1])- (Subscript[a, 0])),  P'(1) =3((Subscript[a, 2])- (Subscript[a, 3])).

One may joint several cubic Bezier curves to form a composite curve. If we choose the joint point on a line that joint the second last point on the first piece to the second point on the second piece, then above property on the derivatives shows that the composite cureve has continuous derivative. Here is an example of two pieces:

Example 2.

XY = {{0.,0.2},{1.,0.},{2.,0.2},{3.,0.75},{4.,1.3},{5.,1.3}, {6.,1.},{6.5,0.85},{6.,0.5},{5.,0.5}};
XY1 = {{0.,0.2},{1.,0.},{2.,0.2},{3.,0.75}}; XY2 = {{3.,0.75},{4.,1.3},{5.,1.3}, {6.,1.}};
XY3 = {{6.,1.},{6.5,0.85},{6.,0.5},{5.,0.5}};
B1[t_] = Bezier[XY1,t]; BX1[x_] = B1[x][[1]]; BY1[x_] = B1[x][[2]]; 
B2[t_] = Bezier[XY2,t]; BX2[x_] = B2[x][[1]]; BY2[x_] = B2[x][[2]];    
B3[t_] = Bezier[XY3,t]; BX3[x_] = B3[x][[1]]; BY3[x_] = B3[x][[2]];

dots = ListPlot[XY,PlotStyle->{PointSize[0.02]},DisplayFunction->Identity];
gr1 = ParametricPlot[{BX1[t],BY1[t]},{t,0,1}, DisplayFunction->Identity];
gr2 = ParametricPlot[{BX2[t],BY2[t]},{t,0,1}, DisplayFunction->Identity];
gr3 = ParametricPlot[{BX3[t],BY3[t]},{t,0,1}, DisplayFunction->Identity];
txt = StringForm["Bezier Curve and Control Points"];
Show[dots,gr1,gr2,gr3,dots, Axes -> False, AspectRatio -> 0.5, DisplayFunction->$DisplayFunction,  PlotLabel->txt]

Show[dots,gr1,gr2,gr3,Graphics[Line[XY]], Axes -> False, AspectRatio -> 0.5, DisplayFunction->$DisplayFunction,  PlotLabel->txt]

Mathematica

Below is the demostration using Mathematica function: BezierCurve[ ]

pts={{0,0},{1,1},{2,1},{3,-1}};
Graphics[{BezierCurve[pts],Green,Line[pts],Red,Point[pts]}]

pts={{0,0},{1,1},{2,-1},{3,1}};
Graphics[{BezierCurve[pts],Green,Line[pts],Red,Point[pts]}]

pts={{0,0},{1,1},{2,-1},{3,0},{5,2},{6,-1},{7,3}};
Graphics[{BezierCurve[pts],Green,Line[pts],Red,Point[pts]}]

pts={{0,0},{0,2/3},{1,2/3},{1,0}, {1,-2/3},{0,-2/3},{0,0}};
Graphics[{BezierCurve[pts],Green,Line[pts],Red,Point[pts]}]

Manipulate[Graphics[{Yellow,Blue,Thick,BezierCurve[pts,SplineDegree->3],FaceForm[],EdgeForm[{Dashed,Red}],Polygon[pts]},Frame->True,PlotRange->5],{{pts,{{-4,-2},{-3,1},{-1,3},{1,2},{4,0},{2,-4},{-2,-4} }},Locator,LocatorAutoCreate->True},"Alt+click to add points"]

Manipulate[Graphics[{Yellow,Blue,Thick,BezierCurve[pts,SplineDegree->3,SplineClosed->True],FaceForm[],EdgeForm[{Dashed,Red}],Polygon[pts]},Frame->True,PlotRange->5],{{pts,{{-4,0},{-3,2},{-1,4},{2,3},{4,0},{2,-4},{0,-2},{-1,-4},{-2,-1},{-3,-2}}},Locator,LocatorAutoCreate->True},"Alt+click to add points"]