% Change the spacing to test each axis or both axes. You get the same
% surface profile whether the spacing is 0.5 or 0.01 on either or both
% Set the smoothness. See the help for details about the
% Calculate surface using cubic interpolation
zCubic = regularizeNd(inputPoints(:, 1:2), inputPoints(:, 3), {x, y}, smoothness, 'cubic');
% zCubic = regularizeNd(inputPoints(:, 1:2), inputPoints(:, 3), {x, y}, smoothness, 'cubic');
% zCubic = regularizeNd(inputPoints(:, 1:2), inputPoints(:, 3), {x, y}, smoothness, 'cubic', 'normal');
% Calculate surface using linear interpolation
zLinear = regularizeNd(inputPoints(:, 1:2), inputPoints(:, 3), {x, y}, smoothness);
% Other equivalent calls. If you use [] for smoothness, interp, or solver,
% the default argument is used. See the help
% zLinear = regularizeNd(inputPoints(:, 1:2), inputPoints(:, 3), {x, y}, smoothness, 'linear');
% zLinear = regularizeNd(inputPoints(:, 1:2), inputPoints(:, 3), {x, y}, smoothness, 'linear', 'normal');
screenSize = get(groot, 'screenSize');
figurePosition = screenSize(3:4)*0.1;
figurePositionAndSize = [figurePosition figureSize];
figure('color', 'w', 'position', figurePositionAndSize)
% Plot this figure on the left.
subplot1 = subplot(1, 2, 1);
view(subplot1,[-74.5, 14]);
% Note that surf uses the meshgrid format for plotting surfaces using
% vectors for x and y. regularizeNd outputs in the ndgrid format. In 2d,
% meshgrid is the transpose of the ndgrid format.
surf(x, y, zCubic', 'facealpha', 0.75);
scatter3(inputPoints(:, 1), inputPoints(:, 2), inputPoints(:, 3),[], 'r', 'filled');
xlabel('x', 'FontSize', 12);
ylabel('y', 'FontSize', 12);
zlabel('z', 'FontSize', 12);
title(sprintf('Regularized output surface generated with cubic Interpolation\nOriginal, scattered input points in red'));
axis([0, 4, 0, 4, 0, 1.1]);
% Plot this figure on the right.
subplot2 = subplot(1, 2, 2);
view(subplot2,[-74.5, 14]);
% Note that surf uses the meshgrid format for plotting surfaces using
% vectors for x and y. regularizeNd outputs in the ndgrid format. In 2d,
% meshgrid is the transpose of the ndgrid format.
surf(x, y, zLinear', 'facealpha', 0.75);
scatter3(inputPoints(:, 1), inputPoints(:, 2), inputPoints(:, 3), [], 'r', 'filled');
xlabel('x', 'FontSize', 12);
ylabel('y', 'FontSize', 12);
zlabel('z', 'FontSize', 12);
title(sprintf('Regularized Output Surface generated with linear Interpolation.\nOriginal, scattered input points in red'));
axis([0, 4, 0, 4, 0, 1.1]);
% Copyright (c) 2016-2026 Jason Nicholson
% Licensed under the MIT License
% See LICENSE file in project root