2D Array Interpolation

后端 未结 2 2008
情话喂你
情话喂你 2020-12-18 09:16

i am currently working on a 3D game in c#. I have a 2 dimensional array called data where i get a z value for my x and y

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 09:44

    You have two known points:

    A = (1,2) = 4
    B = (2,4) = 5
    

    And you want to calculate the value

    C = (1.5, 2.5) = ???
    

    Here's an idea that follows from your linear example. Calculate the linear for each axis. So start with X:

    Ax = (1) = 4
    Bx = (2) = 5
    so you calculate Cx as:
    Cx = (1.5) = 4.5
    

    Then calculate the linear for the y-axis:

    Ay = (2) = 4
    By = (4) = 5
    and calculate Cy as:
    Cy = (2.5) = 4.25
    

    Then average Cx and Cy to get C(x,y)

    C(1.5, 2.5) = (Cx + Cy) * 0.5 = 4.375
    

提交回复
热议问题