B-Spline for 12 nodes

Contents

Nodes Data

x=[0.1 1.1 1.6 2.4 2.5 4.1 5.2 6.1 6.6 7.1 8.2 9.1];
y=[1.9 7.9 24.9 24.9 34.9 42.7 29.7 49.8 36.1 23.7 13.0 20.5];

different Colors for 11 B-spline curves

colors=zeros(11,3);
colors(1,:)=[1 0 0];
colors(2,:)=[1,0,0];
colors(3,:)=[0,1,0];
colors(4,:)=[0,0,1];
colors(5,:)=[0.8,0.0,0];
colors(6,:)=[0,0.8,0];
colors(7,:)=[0,0,0.8];
colors(8,:)=[0.9,0.9,0];
colors(9,:)=[0,0.9,0.9];
colors(10,:)=[0.9,0,0.9];
colors(11,:)=0.7;
colors(12,:)=[0,0,0];
colors(13,:)=[0,0,0];

Data Definitions and initionalizations

N=length(x);                %Number of given Nodes
Ny=length(y);
if(N~=Ny)
   errordlg('Size of x and y must be the same');
   return;
end
if(N<4)
    errordlg('Number of Nodes must not be less than 4');
    return;
end
X=[x(1) x(1) x x(N) x(N)];  %adding two point at the beginning and two in the end
Y=[y(1) y(1) y y(N) y(N)];

n=50;
xb=zeros(n);
yb=zeros(n);

Calculation of B-Splines

plot(x,y,'ro','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','r');
text(0.5,47,'B-Spline Curves','Color',[0 0 1],'FontSize',24,'FontName','Times New Roman');
u=linspace(0,1,n);
ucub=u.^3;
usqr=u.^2;
one_minus_u_cube=(1-u).^3;
k=1;                %Color index
hold on;
for num=1:13
   xb=(1/6)*(one_minus_u_cube*X(num)+...
                (3*ucub-6*usqr+4)*X(num+1)+...
                (3*(-ucub+usqr+u)+1)*X(num+2)+...
                ucub*X(num+3));
   yb=(1/6)*(one_minus_u_cube*Y(num)+...
                (3*ucub-6*usqr+4)*Y(num+1)+...
                (3*(-ucub+usqr+u)+1)*Y(num+2)+...
                ucub*Y(num+3));
   plot(xb,yb,'Color',colors(num,:),'LineWidth',3);
   k=k+1;
   if k>13                  %Colors repeat after 13
       k=1;
   end;
end;
set(gca,'Color',[.2,0.5,.5],'FontSize',12,'FontWeight','bold'); % graph's background color
hold off;