# Interpolate inside cuboid / plane that intersects a point

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.

(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?

• Not enough reputation to embed the image! Sorry folks. If anyone could do this for me that would be fantastic – user495625 Nov 6 '15 at 6:05
• the faces aren't planes, consider (0,0,0),(1,0,0),(0,1,0),(1,1,1) – JonMark Perry Nov 6 '15 at 6:27
• Given the shape of the cuboids as described above, I don't see how any face, or any aL,bL,cL,dL set of coordinates, could ever be badly shaped like that. Could you provide an example? – user495625 Nov 8 '15 at 13:29
• are you just using any 8 points? and why is 'z' pointing downwards? – JonMark Perry Nov 8 '15 at 13:32
• No - the cuboid is always 'sane' (see above). It starts as a cube but is then distorted, just never to the point where it is inside out or anything like that. Z is downwards because I am interpolating for an 3D image where it's (relatively) standard that one dimension is smallest at the top of the screen (just like y in a 2D bitmap). It doesn't really matter though which way z is; the cube could be rotated any which way. – user495625 Nov 8 '15 at 22:59