2014-11-23 152 views

回答

0

從DOC的鏈接,BicubicSplineInterpolator()需要的數據點,以形成網格狀模式。因此,您應該提供x值(長度= m)和y值(長度= m)的數組以及函數值矩陣(長度= mxn)。

0

我同意這些文檔是非常直觀的。更糟糕的是,BicubicSplineInterpolator()是buggy,請參閱https://issues.apache.org/jira/browse/MATH-1166,使用BicubicInterpolator代替http://commons.apache.org/proper/commons-math/changes-report.html

插值使用常規網格(例如3x3網格,並且每個網格點有一個值)。

您需要定義網格位置。 (在這個例子中,我們在x和y方向都有0,128,256,但這些只是數字,你可以在X上有例如溫度和溼度在Y上有不同的範圍)。

然後定義一個矩陣與每個網格點上的實際值一起,創建一個插值器,它將返回一個插值函數,該插值函數可以計算任何x,y處的任何值。

final double[] xValues = new double[] {0,128,256}; 
    final double[] yValues = new double[] {0,128,256}; 

    final double[][] fValues = new double[][] {{1, 0, 1}, 
     {0, 0, 1}, 
     {0, 0, 1}}; 

     final BivariateGridInterpolator interpolator = new BicubicInterpolator(); 
     final BivariateFunction function = interpolator.interpolate(xValues, yValues,fValues); 

     for (int y=0;y<255;y++) { 
      for (int x=0;x<255;x++) { 
       double value=function.value(x, y); 
       // do something with this 
      } 
     }