At the beginning and end, the curve goes to zero
The following is the matlab code
clear,clc;
%%
p = 3; % degree
n = 10; % no.of control points
% control points
x = [1 0.5 5 3 11 8 12 11 15 17];
y = [4 6 4 12 14 4 3 9 10 8];
m = p + n + 1; % no.of knot vector
% specifying t(1:p) = 0, t(m-p:m) = 1
t = zeros(1,m);
t(1:p-1) = 0;
t(end:-1:end-p) = 1;
t(p : end-p+1) = linspace(0,1,size(p:m-p+1,2));
%%
cx = 0; cy = 0;
t_req = 0 : 0.01: 1;
px = zeros(size(t_req));
py = zeros(size(t_req));
pb = zeros(size(t_req));
params.m = m; params.p = p;
params.n = n;
b = zeros(size(t_req,2),size(x,2));
for ct = 1 : size(t_req,2)
cx = 0; cy = 0; b = 0;
for idx = 1 : size(x,2)
basis_fun = N(idx,p,t,t_req(ct),params);
b = b + basis_fun;
cx = cx + x(idx)*basis_fun;
cy = cy + y(idx)*basis_fun;
end
px(ct) = cx;
py(ct) = cy;
pb(ct) = b;
end
%% plotting
figure;
plot(px,py,'b','linewidth',1.3),grid,hold on;
plot(x,y,'r*-.','MarkerSize',7);
%% function to calculate basis_functions
function basis_fun = N(idx,p,t,t_req,params)
if ( p == 0 )
if (t(idx) <= t_req && t(idx+1) > t_req)
basis_fun = 1;
return;
else
basis_fun = 0;
return;
end
else
basis_fun = (t_req - t(idx))/(t(idx+p)-t(idx)) * N(idx,p-1,t,t_req,params) + ...
(t(idx+p+1)-t_req)/(t(idx+p+1)-t(idx+1)) * N(idx+1,p-1,t,t_req,params);
if (isnan(basis_fun) || isinf(basis_fun))
basis_fun = 0;
end
end
end