Linear interpolation of three 3D points in 3D space

batuman picture batuman · Sep 12, 2013 · Viewed 10.8k times · Source

I have three 3D points like p1(x1,y1,z1), p2(x2,y2,z2), p3(x3,y3,z3). I have another point, but I know only x, y value of that point like p4(x4,y4,Z), in which Z is the value I like to compute.

I am sure p4(x4,y4) point is inside a triangle formed by p1(x1,y1), p2(x2,y2), p3(x3,y3) by checking with delaunay triangulation approach. How can I compute Z value of point p4? I like to implement it in C programming. Actually I am trying to implement griddata in MATLAB.

Thanks

Answer

DanielKO picture DanielKO · Sep 12, 2013

p1, p2, p3 define a plane. You can represent it by a point and a normal. For instance, P=p1, N=(p2-P) x (p3-P) (that is, N = cross product of p1p2 and p1p3).

Now for p4 to be in the same plane, it satisfies the plane equation:

  (p4-P) · N = 0  %// dot product
⇒ (x4-x1)*N.x + (y4-y1)*N.y + (z4-z1)*N.z = 0

Re-arranging:

z4 = z1 - ((x4-x1)*N.x + (y4-y1)*N.y)/ N.z

No linear system to solve, you just need a cross product.