function out=plotdecas2D(cp,r,s,num)

% PLOTDECAS2D plots a planar curve using the de Casteljau algorithm to
% compute num points on the curve. The curve is defined by the control
% points in cp with respect to an affine frame [r,s]. The point we want
% to compute corresponds to the interpolation value t in [r,s].

if (nargin ~= 4)
  error('Incorrect number of arguments');
end

if (size(cp,1) ~= 2)
  error('Sorry, I can only plot planar curves');
end

if (r == s)
  error('Incorrect input affine basis');
end
  
if (num < 2)
  error('Number of points must be greater than 1');
end

x = zeros(2,num);
d = (s - r) / (num-1);

for i = 0:num-1
  t = r + ((i / (num-1)) * (s - r));  
  x(:,i+1) = decas(cp,r,s,t);
end

out = x;

plot(x(1,:),x(2,:),'g');
hold on;
plot(cp(1,:),cp(2,:),'ro--');
hold off;

return
