* <p>
* z = 2 x<sup>2</sup> - 3 y<sup>2</sup> + 4 x y - 5
*/
@Test
public void testParaboloid() throws MathException {
BivariateRealFunction f = new BivariateRealFunction() {
public double value(double x, double y) {
return 2 * x * x - 3 * y * y + 4 * x * y - 5
+ ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
}
};
BivariateRealGridInterpolator interpolator = new SmoothingPolynomialBicubicSplineInterpolator(4);
double[] xval = new double[] {3, 4, 5, 6.5};
double[] yval = new double[] {-4, -3, -2, -1, 0.5, 2.5};
double[][] zval = new double[xval.length][yval.length];
for (int i = 0; i < xval.length; i++) {
for (int j = 0; j < yval.length; j++) {
zval[i][j] = f.value(xval[i], yval[j]);
}
}
BivariateRealFunction p = interpolator.interpolate(xval, yval, zval);
double x, y;
double expected, result;
x = 5;
y = 0.5;
expected = f.value(x, y);
result = p.value(x, y);
Assert.assertEquals("On sample point", expected, result, 2);
x = 4.5;
y = -1.5;
expected = f.value(x, y);
result = p.value(x, y);
Assert.assertEquals("half-way between sample points (middle of the patch)", expected, result, 2);
x = 3.5;
y = -3.5;
expected = f.value(x, y);
result = p.value(x, y);
Assert.assertEquals("half-way between sample points (border of the patch)", expected, result, 2);
}