protected void buildGrid(int numX,
int numY,
int power) {
int numValues = numX * numY;
double[] xGrid = new double[numValues];
double[] yGrid = new double [numValues];
double[] zGrid = new double [numValues];
// Find min, max for the x and y axes
double xMin = 1.e20;
for (int k = 0; k < this.xValues.length; k++) {
xMin = Math.min(xMin, this.xValues[k].doubleValue());
}
double xMax = -1.e20;
for (int k = 0; k < this.xValues.length; k++) {
xMax = Math.max(xMax, this.xValues[k].doubleValue());
}
double yMin = 1.e20;
for (int k = 0; k < this.yValues.length; k++) {
yMin = Math.min(yMin, this.yValues[k].doubleValue());
}
double yMax = -1.e20;
for (int k = 0; k < this.yValues.length; k++) {
yMax = Math.max(yMax, this.yValues[k].doubleValue());
}
Range xRange = new Range(xMin, xMax);
Range yRange = new Range(yMin, yMax);
xRange.getLength();
yRange.getLength();
// Determine the cell size
double dxGrid = xRange.getLength() / (numX - 1);
double dyGrid = yRange.getLength() / (numY - 1);
// Generate the grid
double x = 0.0;
for (int i = 0; i < numX; i++) {
if (i == 0) {
x = xMin;
}
else {
x += dxGrid;
}
double y = 0.0;
for (int j = 0; j < numY; j++) {
int k = numY * i + j;
xGrid[k] = x;
if (j == 0) {
y = yMin;
}
else {
y += dyGrid;
}
yGrid[k] = y;
}
}
// Map the nongrid data into the new regular grid
for (int kGrid = 0; kGrid < xGrid.length; kGrid++) {
double dTotal = 0.0;
zGrid[kGrid] = 0.0;
for (int k = 0; k < this.xValues.length; k++) {
double xPt = this.xValues[k].doubleValue();
double yPt = this.yValues[k].doubleValue();
double d = distance(xPt, yPt, xGrid[kGrid], yGrid[kGrid]);
if (power != 1) {
d = Math.pow(d, power);
}
d = Math.sqrt(d);
if (d > 0.0) {
d = 1.0 / d;
}
else { // if d is real small set the inverse to a large number
// to avoid INF
d = 1.e20;
}
if (this.zValues[k] != null) {
// scale by the inverse of distance^power
zGrid[kGrid] += this.zValues[k].doubleValue() * d;
}
dTotal += d;
}
zGrid[kGrid] = zGrid[kGrid] / dTotal; //remove distance of the sum
}
//initalize xValues, yValues, and zValues arrays.
initialize(
formObjectArray(xGrid), formObjectArray(yGrid),
formObjectArray(zGrid)
);
} Deprecated!Builds a regular grid. Maps the non-grid data into the regular grid
using an inverse distance between grid and non-grid points. Weighting
of distance can be controlled by setting through the power parameter
that controls the exponent used on the distance weighting
(e.g., distance^power). |