1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.analysis.interpolation;
23
24 import org.hipparchus.exception.LocalizedCoreFormats;
25 import org.hipparchus.exception.MathIllegalArgumentException;
26 import org.hipparchus.util.MathArrays;
27 import org.hipparchus.util.MathUtils;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class BicubicInterpolator
46 implements BivariateGridInterpolator {
47
48
49
50
51
52
53
54
55 public BicubicInterpolator() {
56
57 }
58
59
60
61
62 @Override
63 public BicubicInterpolatingFunction interpolate(final double[] xval,
64 final double[] yval,
65 final double[][] fval)
66 throws MathIllegalArgumentException {
67 if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
68 throw new MathIllegalArgumentException(LocalizedCoreFormats.NO_DATA);
69 }
70 MathUtils.checkDimension(xval.length, fval.length);
71 MathArrays.checkOrder(xval);
72 MathArrays.checkOrder(yval);
73
74 final int xLen = xval.length;
75 final int yLen = yval.length;
76
77
78 final double[][] dFdX = new double[xLen][yLen];
79 final double[][] dFdY = new double[xLen][yLen];
80 final double[][] d2FdXdY = new double[xLen][yLen];
81 for (int i = 1; i < xLen - 1; i++) {
82 final int nI = i + 1;
83 final int pI = i - 1;
84
85 final double nX = xval[nI];
86 final double pX = xval[pI];
87
88 final double deltaX = nX - pX;
89
90 for (int j = 1; j < yLen - 1; j++) {
91 final int nJ = j + 1;
92 final int pJ = j - 1;
93
94 final double nY = yval[nJ];
95 final double pY = yval[pJ];
96
97 final double deltaY = nY - pY;
98
99 dFdX[i][j] = (fval[nI][j] - fval[pI][j]) / deltaX;
100 dFdY[i][j] = (fval[i][nJ] - fval[i][pJ]) / deltaY;
101
102 final double deltaXY = deltaX * deltaY;
103
104 d2FdXdY[i][j] = (fval[nI][nJ] - fval[nI][pJ] - fval[pI][nJ] + fval[pI][pJ]) / deltaXY;
105 }
106 }
107
108
109 return new BicubicInterpolatingFunction(xval, yval, fval,
110 dFdX, dFdY, d2FdXdY) {
111
112 @Override
113 public boolean isValidPoint(double x, double y) {
114 if (x < xval[1] ||
115 x > xval[xval.length - 2] ||
116 y < yval[1] ||
117 y > yval[yval.length - 2]) {
118 return false;
119 } else {
120 return true;
121 }
122 }
123 };
124 }
125 }