I’m using TGraph2D::Interpolate on a 2D set of points defining my surface. I find a very strange behavior: when calling Interpolate with the coordinates of one point as arguments, the returned value is wrong. If I use inter-point coordinates the returned value seems correct.
To be more clear, I run this code (compiled with GCC):
TGraph2D graph;
for (int iX = 0; iX < 20; iX++){
for (int iY = 0; iY < 20; iY++){
graph.SetPoint(graph.GetN(), iX, iY, iY);
}
}
std::cout << graph.Interpolate(1, 1) << std::endl;
std::cout << graph.Interpolate(1.001, 1) << std::endl;
std::cout << graph.Interpolate(0.999, 1) << std::endl;
I’d expect always 1 as output, but instead I get:
1.019
1
1
That is, when using the exact coordinates of one of the points defining the TGraph2D the interpolation returns a wrong result (which is pretty weird since there’s nothing to interpolate, actually). But if I move slightly away from the point then the interpolation returns the correct result. This seems to be somehow related to the number of points: for a 5x5 mesh defined as above one gets 1.004 instead of 1.019.
The documentation of TGraph2D states:
The 20x20 grid of my example seems to fit into this definition; anyway, at most I’d expect that the algorithm would fail when interpolating far away from the points, not when lying exactly on one of them…
I’m using Root 5.34.10. Thanks