# Trilinear interpolation for distorted cubes?

Is there a variation of trilinear interpolation that works on a "cube" that has been distorted (by moving one or more of its corners by an arbitrary amount into an arbitrary direction)?

I know that I could use the inverse of the distance to each of the 8 corners as weights to get an interpolated point within the distorted cube, but that would involve taking a lot of square roots which would slow my algorithm way down. I like the elegant way of trilinear interpolation but I can't figure out how to adapt it to a distorted cube. Any hint on a fast interpolation method for this situation would be much appreciated.

• Can you explain what trilinear interpolation is? – Yuval Filmus Nov 9 '17 at 14:34
• It combines two bilinear and one linear interpolation to find the value of a feature at a known coordinate within a cube of which you know the values of that feature for the 8 cube corners: en.wikipedia.org/wiki/Trilinear_interpolation – Simeon Nov 9 '17 at 14:45
• Are you also assuming that the values are linear in all cardinal directions? – Yuval Filmus Nov 9 '17 at 14:46
• Yes, for my application I assume the values are linear. My features are basically 3D coordinates. My input are coordinates in a distorted cube and I want to know the coordinates if you were to un-distort the cube (back to a unit cube). The distortion (by way of moving the cube corners) is supposed to be linear. – Simeon Nov 9 '17 at 14:53

## 1 Answer

Imagine a cube with each corner a different RGB color value - as you know you could interpolate the colors inside the cube using trilinear interpolation.

You can reuse this same logic for coordinates as well -- set the RGB values of the corners to be the XYZ coords of your distorted cube's corners.

Now the RGB "color" you sample in this cube is the distorted coordinate -- eg, it is the coordinate of your sampling point after that point has been "remapped" to the now-distorted cube, using the normal trilinear algorithm.

Hope this helps.