%% 2-D Interpolation
% Define some sample points and calculate the value of a trigonometric function at those locations. These points are the sample values for the interpolant.

t = linspace(3/4*pi,2*pi,50)';
x = [3*cos(t); 2*cos(t); 0.7*cos(t)];
y = [3*sin(t); 2*sin(t); 0.7*sin(t)];
v = repelem([-0.5; 1.5; 2],length(t));

%
% Create the interpolant.

F = scatteredInterpolant(x,y,v);

%
% Evaluate the interpolant at query locations (xq,yq).

tq = linspace(3/4*pi+0.2,2*pi-0.2,40)';
xq = [2.8*cos(tq); 1.7*cos(tq); cos(tq)];
yq = [2.8*sin(tq); 1.7*sin(tq); sin(tq)];
vq = F(xq,yq);

%
% Plot the result.

plot3(x,y,v,'.',xq,yq,vq,'.'), grid on
title('Linear Interpolation')
xlabel('x'), ylabel('y'), zlabel('Values')
legend('Sample data','Interpolated query data','Location','Best')

% Copyright 2015 The MathWorks, Inc.