5

For my project I have to write a C++ code, equivalent to the ScatteredInterpolant() function of Matlab. My data points are scattered data in three dimension. I am able to calculate the Delaunay tetrahedrals using the TetGen library. I have compared the interpolation results using the tetrahedrals found from the TetGen and from the Matlab's own delaunay() function, the results are same as long as the query point is within the convex hull.

In my project, I have to extrapolate for the points outside the convex hull using linear extrapolation. I went through the Matlab documentation, and it says "Linear extrapolation based on boundary gradients." From my literature survey I could not find good documentation how the linear extrapolation work using the boundary gradients. I would really appreciate if you provide me insight how the linear extrapolation work for scatteredInterpolant().

I have looked into the scattered-data-extrapolation documentation page, which says " The 'linear' extrapolation method is based on a least-squares approximation of the gradient at the boundary of the convex hull. The values it returns for query points outside the convex hull are based on the values and gradients at the boundary." To verify, I have written the following code (2D data):

clc;clear;close all;

x = [ -1 1 1 -1 0 ]; y = [ -1 -1 1 1 0 ];

v = x.^2 + y.^2;

tri = delaunay(x, y);

F = scatteredInterpolant(x(:), y(:), v(:), 'linear', 'linear');

[xq, yq] = meshgrid( -2 : 0.1 : 2 );

vq = F(xq, yq);

figure; plot(x, y, 'r*');hold on; tri = delaunay(x, y); triplot(tri, x, y); xlabel('x');ylabel('y'); scatter3(x, y, v, 'r', 'filled');hold on; surf(xq, yq, vq); text(x(1), y(1), '1', 'fontsize', 20); text(x(2), y(2), '2', 'fontsize', 20); text(x(3), y(3), '3', 'fontsize', 20); text(x(4), y(4), '4', 'fontsize', 20); text(x(5), y(5), '5', 'fontsize', 20); box on; xlabel('x');ylabel('y'); set(gca, 'fontsize', 16);

enter image description here enter image description here From my understanding the slope is 2, but why the extrapolated value is different? I may be missing something. I would really appreciate some insight.

Thank you

gman
  • 157
  • 1
  • 3
  • 13
  • Excuse me sir, I have been looking for ScatterInterpolant c++ code equivalent to the Matlab one , could you kindly share the code that you wrote ? – zeellos Feb 19 '23 at 20:08

0 Answers0