# TH3 - interpolate?

Hello,

I would like to interpolate a vector field which is just given at certain points in cylindrical coordinates. As I found out, for 2D coordinates there is the possibility to use
TGraph2D::Interpolate(x,y) (or the same for TH2)

I am searching something similar for a TH3 objects. The interpolate functionality is probably (or obviously) not implemented since I get the following error when i try to use it …
" Error in TH3D::Interpolate: This function is not yet implemented for a TH3 "

Is there another possibility within root to do what I want? Namely, to interpolate a function like f(x,y,z) at any point within its domain?

Best regards,
Stefan

Hi,

the TGraph2D::Interpolate and TH2::Interpolate are two different algorithms. The first one works for any points, while the latter works only on a regular grid.
For 3 dimensions, we don;t have presently anything in ROOT. An algorithm working on a regular grid, like TH3::Interpolate, could be implemented for the next release. Would be this fine for you ? Let me know,

Best Regards

Lorenzo

So the difference between the two algorithms is just that the points, which have to be interpolated, have to be on an regular grid in case of TH2 (and TH3). That’s not a problem for me.
But the coordinates where I would like to evaluate the field (interpolate the regular grid) can be everywhere then, when I use the TH3::Interpolate, right?

If true, I would be very happy about such an implementation! Please give me a word when it’s in the trunk (so I don’t have to wait for the next release )

Stefan

Lorenzo[/quote]

Hi,

one can evaluate the interpolation result at any point (x,y,z) in the histogram range.
I will then let you know when the trilinear interpolation is in the trunk

Best Regards

Lorenzo

Hi,

How big is the chance that also an higher order Interpolation like tri-cubic could be implemented?

However, I know that you are of course busy but what would be an rough estimate on when the tri-linear interpolation would be available?

Greetings,
Stefan

Hi,

I have added now the tri-linear interpolation of a TH3 in the trunk.

I have no plan so far to include a cubic interpolation in 2D or 3D. For 1D we have the spline classes.
If you want to contribute with it, we would be very grateful,

Best Regards

Lorenzo

Hi

Many thanks for the implementation. Just one remark: You do not count the border itself (middle position of the border bins) as to be within the domain? … please see attached example …
Would it be possible to include this as well?

Regarding the tricubic interpolation: There is such an implementation which can be found at
gyre.cds.caltech.edu/pub/software/tricubic/doc/
… but I am not sure if I find the time to write something similar for TH3 object …

Thanks,
Stefan
Macro3Dinterp.C (1.57 KB)

Hi,
the interpolation requires the point to be between the first and the last bin center. It is an interpolation and not an extrapolation.
Probably is not right to return a zero value outside this range, but maybe
just the bin center value when x is in the histogram range and the underflow/overflow value outside.

Lorenzo

Hi,

the interpolation requires the point to be between the first and the last bin center.
It is an interpolation and not an extrapolation.

ok, I think that depends on the definition whether the bin center itself is still an interpolation in 2D (or 3D), since it might be on the exact last bin center position in x direction, but somewhere within the interpolation range in y. This would result in a 1 dim. interpolation between the bins in y direction (which are the last bins in x) … and something similar for the 3D case …

Probably is not right to return a zero value outside this range, but maybe
just the bin center value when x is in the histogram range and the underflow/overflow
value outside.

Yap, that sound more reasonable to me …

Stefan