% Example illustrating the use of
% parametric cubic spline to interpolate in 2D.
% cubicSpline2D.m
% K. Ming Leung, 03/08/03

clear all; hold off; nPlotPts=10;
% The exact function to be interpolated
fx=inline('t.*(1+t.*(-0.6+t.*(0.1)))','t');
fy=inline('1./(1+(t-1).^2)','t');
t=0:0.01:4;
x=fx(t); y=fy(t);
plot(x,y,'k-','lineWidth',2); hold on;

% Cubic spline interpolation using 5 points:
% Create input data
ti5=linspace(0,4,5)'; 
xi5=fx(ti5); 
yi5=fy(ti5);
% Parametric cubic spline interpolation
[tPlotx, xPlot5] = cubicSplineNaturalF(ti5,xi5,nPlotPts); 
[tPloty, yPlot5] = cubicSplineNaturalF(ti5,yi5,nPlotPts);
plot(xPlot5,yPlot5,'b--'); 

% Cubic spline interpolation using 8 points:
% Create input data
ti8=linspace(0,4,8)'; 
xi8=fx(ti8); 
yi8=fy(ti8);
% Parametric cubic spline interpolation
[tPlotx, xPlot8] = cubicSplineNaturalF(ti8,xi8,nPlotPts); 
[tPloty, yPlot8] = cubicSplineNaturalF(ti8,yi8,nPlotPts);
plot(xPlot8,yPlot8,'r--');

axis equal;
legend('Exact','N=5','N=8',3);

% Plot the actual points used in interpolation
plot(xi5,yi5,'b.','markerSize',14); 
plot(xi8,yi8,'r.','markerSize',14); 

ylabel('y','FontSize',18);
xlabel('x','FontSize',18); 
title('Parametric Cubic Spline','FontSize',24);
