I'm looking for a function in PHP for interpolating a set of irregular placed data (x,y,z) to a gridded data set for using it in ContourPlot function in JPGraph. I've developed a function based on simple Inverse distance weighting, but it is too slow. I need to use another method like "Modified Shepard's Method" or any other possible methods with more accuracy to make it faster and smoother.
Here is my current code:
for($i = 0, $ij = 0; $i < $gridX; $i ++) {
for($j = 0; $j < $gridY; $j ++, $ij ++) {
$x = $startP->x + ($deltaX * $i);
$y = $startP->y + ($deltaY * $j);
$g [$ij]->i = $i;
$g [$ij]->j = $j;
$g [$ij]->x = ( int ) $x;
$g [$ij]->y = ( int ) $y;
$g [$ij]->z = IDW_U ( $x, $y, $sampleData, $sampleSize, $p );
}
}
function IDW_U($x, $y, $data, $size, $p) {
$idw_sum = IDWeightSum ( $x, $y, $data, $size, $p );
$idw_u = 0.0;
for($k = 0; $k < $size; $k ++) {
if ($x == $data [$k]->x && $y == $data [$k]->y)
return $data [$k]->z;
$idw_u += IDWeight ( $x, $y, $data [$k], $p ) * $data [$k]->z / $idw_sum;
}
return $idw_u;
}
function IDWeightSum($x, $y, $data, $size, $p) {
$sum = 0.0;
for($k = 0; $k < $size; $k ++)
$sum += IDWeight ( $x, $y, $data [$k], $p );
return $sum;
}
function IDWeight($x, $y, $d, $p) {
if ($x == $d->x && $y == $d->y)
return 1.0;
$dx = $x - $d->x;
$dy = $y - $d->y;
$ret = 1.0 / pow ( sqrt ( pow ( $dx, 2 ) + pow ( $dy, 2 ) ), $p );
return $ret;
}
Does anybody know a function or library available for this purpose?