How to disable Interpolation out of range of TGraph2D

Dear experts

I have a TGraph2D that contains a set of points, the boundary is not a circle or square but an irregular shape. When I use TGraph2D::Interpolation, due to the triangle interpolation some out-of-range position will be interpolated which is not what I expected, is there any way to disable it? I attach the view of the boundary and the unexpected region.

Hi,

Can you just draw the points?

D

How did you produce this picture ? @Danilo is right you can just draw the points.

Thank you for the reply, my question is not about drawing points. I want to do interpolation when I give a position which inside the boundary, but I don’t want to interpolate out of the boundary as I showed above (since it’s not “interpolation”). The problem is TGraph2D::Interpolate() is using Delaunay triangulation so somewhere like (1, 0.5) in the graph above will give a strange interpolation result. Can I somehow disable the interpolation only for the region that out of boundary?

I see. Can you provide a small example demonstrating this “strange interpolation result” ?

Here is the plot I showed above. You can see the region I mentioned above will result in strange interpolation value.
graph.root (215.6 KB)

Seems to me, when the (x,y) point is not below/above a triangle ie: outside the interpolation area, 0 is returned:

root [1] Graph2D->Draw()
root [2] Graph2D->Interpolate(0,0)
(double) 1.0000000e-09
root [3] Graph2D->Interpolate(100,100)
(double) 0.0000000
root [4] Graph2D->Interpolate(-10,-10)
(double) 0.0000000

If the point is out of a triangle it’s 0, that’s fine. But when It’s in a triangle but out of boundary like (10, 5), it returns an unexpected interpolated value. If you draw the plot by TRI option you can see it. The reason is that region near (10,5) should not be interpolated but extrapolated.

It might be you have duplicate point. Let me finish something urgent and I will check.

Thank you! If you draw it with option TRI and move to “top view” (make Z axis disappear) you can see the region I mentioned.

I see . There is no duplicates. The algorithm does the triangulation this way. It cannot find out that you do not expect these triangles to not be part of the data set. It always defines as many triangles as it could.

I see, so it means there is no way to disable the interpolation of those triangles unless I made another algorithm to identify the boundary?

yes, for the triangulation algorithm those triangles do not have anything special and are part of the global triangulation.

Thank you for your explanation!

1 Like

Sorry I have a small question of the source code of TGraph2D::Interpolate: 1243,

 if (!TestBit(kOldInterpolation) )

May I ask what does this line mean and when it will return true? I found if this returns true ROOT will find TGraphDelaunay2D which should not make triangles out of the concave curve as described here

Ah I see, TGraph2D is doing an unconstrained Delaunay Triangulation since no edges is passed to it. Is there a way to pass edges to let TGraph2D make a constrained triangulation?

The Delaunay triangulation is done ultimately by the CDT package call by
Delaunay2D. May be CDT can be instructed to use a constrained triangulation. This need to be checked.

In my case, the points are actually a grid with constant interval (0.1 x 0.1), so I can delete triangles that circumscribed circles that radius larger than sqrt(0.1x0.1 + 0.1x0.1) to get rid of triangles out of boundary. I see CDT have functions to erase triangles, but seems there is no accessor in the Delaunay2D?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.