regularizeNd can handle issues near convex hull that scatteredInterpolant can't
This example was adapted from the scatteredInterpolant examples from Mathworks.
This example shows an interpolated surface that deteriorates near the convex hull for scatteredInterpolant. regularizeNd can approximate the surface hear the convex hull without problem. Note that regularizeNd is not an interpolant. It is a fitting algorithm. The surface is an approximation and not an interpolated surface.
Create a sample data set that will exhibit problems near the boundary.
x3 = linspace(-0.3,0.3,16)';
xlabel('x'); ylabel('y');
title('x-y ponts used to create surface');
Now lift these sample points onto the surface
and interpolate the surface. F = scatteredInterpolant(x,y,z);
[xi,yi] = ndgrid(-0.3:.02:0.3, -0.0688:0.01:0.0688);
xGrid = {linspace(min(x)-eps(min(x)), max(x)+eps(max(x)), 20), linspace(min(y)-eps(min(y)), max(y)+eps(max(y)), 21)};
zGrid = regularizeNd([x,y], z, xGrid, [0.001, 0.005], 'linear');
F2 = griddedInterpolant(xGrid, zGrid, 'linear');
xlabel('X','fontweight','b'), ylabel('Y','fontweight','b')
zlabel('Value - V','fontweight','b')
title('scatteredInterpolant vs. Regularized Surface');
legend({'scatteredInterpolant Surface', 'regularized surface'}, 'location', 'best')
The actual surface is:
To understand why the interpolating surface deteriorates near the boundary, it is helpful to look at the underlying triangulation:
dt = delaunayTriangulation(x,y);
title('Triangulation Used to Create the scatteredInterpolant')
The triangles within the red boundaries are relatively well shaped; they are constructed from points that are in close proximity and the interpolation works well in this region. Outside the red boundary, the triangles are sliver-like and connect points that are remote from each other. There is not sufficient sampling to accurately capture the surface, so it is not surprising that the results in these regions are poor. In 3-D, visual inspection of the triangulation gets a bit trickier, but looking at the point distribution can often help illustrate potential problems.
% Copyright (c) 2016-2026 Jason Nicholson
% Licensed under the MIT License
% See LICENSE file in project root