bilinear interpolation of an array c#

匆匆过客 提交于 2019-12-10 12:26:42

问题


I have an array[160,160] with 27 measured datapoints and want to interpolate the whole array. I have found the following code, but don't get it which parameters I have to hand over so that this method works:

 public static double BilinearInterpolation(double[] x, double[] y, double[,] z, double xval, double yval)
            {
                //calculates single point bilinear interpolation
                double zval = 0.0;
                for (int i = 0; i < x.Length - 1; i++)
                {
                    for (int j = 0; j < y.Length - 1; j++)
                    {   
                        if(xval>=x[i] && xval<x[i+1] && yval>=y[j] && yval<y[j+1])
                        {
                        zval = z[i,j]*(x[i+1]-xval)*(y[j+1]-yval)/(x[i+1]-x[i])/(y[j+1]-y[j])+
                               z[i+1,j]*(xval-x[i])*(y[j+1]-yval)/(x[i+1]-x[i])/(y[j+1]-y[j])+
                               z[i,j+1]*(x[i+1]-xval)*(yval-y[j])/(x[i+1]-x[i])/(y[j+1]-y[j])+
                               z[i+1,j+1]*(xval-x[i])*(yval-y[j])/(x[i+1]-x[i])/(y[j+1]-y[j]);
                        }
                    }
                }
                return zval;
            }

           public static double[] BilinearInterpolation(double [] x, double[] y, double[,]z,double[] xvals, double[]yvals)
           {
               //calculates multiple point bilinear interpolation
               double[] zvals = new double[xvals.Length];
               for (int i = 0; i < xvals.Length; i++)
                   zvals[i] = BilinearInterpolation(x, y, z, xvals[i], yvals[i]);
               return zvals;
           }

double[] x --> the x koordinates of my points in an array?

double[] y --> the y koordinates of my points in an array?

double[,] z --> an array, where the interpolated values get stored?

double xval --> ??

double yval --> ??

is this correct? or maybe you have a easier way to interpolate the array bilinear.


回答1:


Looks to me like xval and yval are the values at which you want to interpolate. These are the coordinates of the point that you want evaluated.



来源:https://stackoverflow.com/questions/23671015/bilinear-interpolation-of-an-array-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!