Interpolate inside cuboid / plane that intersects a point

315 Views Asked by At

I am trying to implement a trilinear interpolation algorithm for cuboids.

Please excuse my lack of math jargon, this is not my area!

The cuboids can be rotated in any dimension in 3D space. No two faces are guaranteed to face one another precisely or be exactly the same shape. The cuboids are always 'sane' - never twisted to the point where you could consider lines to be crossing, not flat, no two points are in the same position, etc.

cuboid example

(Please note that the eight points have different values - I've coloured the planes in this image simply so it's easier to see)

Let p be the point in 3D space I need to interpolate (p is guaranteed to be inside the cuboid). Let $a_1,b_1,c_1,d_1$ be four points on one face; and $a_2,b_2,c_2,d_2$ be their corresponding points on another face.

Let L be a value between 0 and 1, describing the proportional distance between two corresponding points (e.g. $a_1, a_2$).

I understand that my problem boils down to finding L, so that the plane $a_L,b_L,c_L,d_L$ intersects point p. From here interpolation is simple.

How do I find L? Is there a simpler way to do this?