TricubicInterpolatingFunction implements TrivariateFunction { public double value(double x, double y, double z) throws OutOfRangeException { final int i = searchIndex(x, xval); if (i == -1) { throw new OutOfRangeException(x, xval[0], xval[xval.length - 1]); } final int j = searchIndex(y, yval); if (j == -1) { throw new OutOfRangeException(y, yval[0], yval[yval.length - 1]); } final int k = searchIndex(z, zval); if (k == -1) { throw new OutOfRangeException(z, zval[0], zval[zval.length - 1]); } final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]); final double yN = (y - yval[j]) / (yval[j + 1] - yval[j]); final double zN = (z - zval[k]) / (zval[k + 1] - zval[k]); return splines[i][j][k].value(xN, yN, zN); } TricubicInterpolatingFunction(double[] x,
                                         double[] y,
                                         double[] z,
                                         double[][][] f,
                                         double[][][] dFdX,
                                         double[][][] dFdY,
                                         double[][][] dFdZ,
                                         double[][][] d2FdXdY,
                                         double[][][] d2FdXdZ,
                                         double[][][] d2FdYdZ,
                                         double[][][] d3FdXdYdZ); double value(double x, double y, double z); boolean isValidPoint(double x, double y, double z);  }
@Test public void testWave() { final double a = 5; final double omega = 0.3; final double kx = 0.8; final double ky = 1; final TrivariateFunction arg = new TrivariateFunction() { public double value(double x, double y, double z) { return omega * z - kx * x - ky * y; } }; final TrivariateFunction f = new TrivariateFunction() { public double value(double x, double y, double z) { return a * FastMath.cos(arg.value(x, y, z)); } }; final TrivariateFunction dfdx = new TrivariateFunction() { public double value(double x, double y, double z) { return kx * a * FastMath.sin(arg.value(x, y, z)); } }; final TrivariateFunction dfdy = new TrivariateFunction() { public double value(double x, double y, double z) { return ky * a * FastMath.sin(arg.value(x, y, z)); } }; final TrivariateFunction dfdz = new TrivariateFunction() { public double value(double x, double y, double z) { return -omega * a * FastMath.sin(arg.value(x, y, z)); } }; final TrivariateFunction d2fdxdy = new TrivariateFunction() { public double value(double x, double y, double z) { return -ky * kx * a * FastMath.cos(arg.value(x, y, z)); } }; final TrivariateFunction d2fdxdz = new TrivariateFunction() { public double value(double x, double y, double z) { return omega * kx * a * FastMath.cos(arg.value(x, y, z)); } }; final TrivariateFunction d2fdydz = new TrivariateFunction() { public double value(double x, double y, double z) { return omega * ky * a * FastMath.cos(arg.value(x, y, z)); } }; final TrivariateFunction d3fdxdydz = new TrivariateFunction() { public double value(double x, double y, double z) { return omega * ky * kx * a * FastMath.sin(arg.value(x, y, z)); } }; testInterpolation(-10, 3, 4.5, 6, -150, -117, 30, 5000, f, dfdx, dfdy, dfdz, d2fdxdy, d2fdxdz, d2fdydz, d3fdxdydz, 1e-3, 1e-2, 1e-12, false); }