function [r,d] = rational_bezier_curve(c,w,t) 
% RATIONAL_BEZIER_CURVE: evaluation of a rational Bezier curve 
% [r,d] = rational_bezier_curve(c,w,t) 
% points r(j,:) at t(j) and weight points d(i,:) 
% for a rational Bezier curve 
% with control points c(k,:) and weights w

% convert to column vector (if necessary)
w = w(:);

% degree and dimension
[np1,dim] = size(c);

% homogeneous control points
W = repmat(w,1,dim);
cw = [W.*c w];

% evaluation
r = casteljau(cw,t);
r= r(:,1:end-1)./repmat(r(:,end),1,dim);

% weight points
K = [1:np1-1];
d = (W(K,:).*c(K,:)+W(K+1,:).*c(K+1,:))./(W(K,:)+W(K+1,:));

