function [ ] = bezier( p1, p2, p3, p4 )
%BEZIER Draws a cubic Bezier curve with control points p1, p2, p3, and p4.
% Each control point is represented as a 2-element vector whose first
% element is the point's X coordinate and whose second element is its Y
% coordinate.

t = linspace( 0, 1, 200 );

x = (1-t).^3 .* p1(1) + 3 * t .* (1-t).^2 .* p2(1) ...
    + 3 * t.^2 .* (1-t) .* p3(1) + t.^3 .* p4(1);
y = (1-t).^3 .* p1(2) + 3 * t .* (1-t).^2 .* p2(2) ...
    + 3 * t.^2 .* (1-t) .* p3(2) + t.^3 .* p4(2);

plot( x, y );

end

