How does the linear-interpolation with three variables work?

3.2k Views Asked by At

For creating a topdown 2D Landscape I use ValueNoise. However I have to interpolate between points and I´m wondering how to do that. Every point(x|y) has a z-value(the height) -> 3 variables.

I know Linear Interpolation with 2 variables, but I don´t know how to archieve Linear Interpolation with 3 variables. There are some examples on the internet, but I just don´t understand them. At school I learned nothing about xyz-coordinate-systems because I´m quite young.

How I interpolate with 2 variables:

For example I have these coordinates:

 P0(0|5),P1(1|NULL),P2(2|NULL),P3(3|NULL),P4(4|20)

1.) To get f(1), f(2) and f(3) I have to calculate the slope m by using two defined points (P0 and P4).

formula: m = (y1-y2) / (x1-x2)
-> m = (5-20) / (0-4) = -15/-4 = 3.75

-> m = 3.75

2.) Now I can calculate my missing y-coordinates by using one defined point like (0|5) or (4|20) and m (in this example I use P0(0|5)):

 formula: y1 = (-m) * ( x2 - x1 ) + y2

 P1(1|?) -> ? = (-3.75) * ( 0 - 1 ) + 5
         -> ? = 8.75
 ----> P1(1|8.75)

This way I can calculate all my missing y-coordinates. Thats how I do linear interpolation with two variables(x,y).

Hope you can help me.