function out=decas(cp,r,s,t)

% DECAS computes a point on a curve using the de Casteljau algorithm.
% 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

n = size(cp,2);

if (n < 2)
  error('Insufficient number of control points');
end
  
if (r == s)
  error('Incorrect input affine basis');
end

x = cp;

for j = 1 : (n - 1)
  for i = 1 : n - j
    x(:,i) = lerp(x(:,i),x(:,i+1),r,s,t);
  end
end

out = x(:,1);

return