const isEllipsoidInside = (x, y, z, centerX, centerY, centerZ, a, b, c) => {
let minX = centerX - a;
let maxX = centerX + a;
let minY = centerY - b;
let maxY = centerY + b;
let minZ = centerZ - c;
let maxZ = centerZ + c;
if (x < minX || x > maxX || y < minY || y > maxY || z < minZ || z > maxZ) {
return false;
}
return ((x - centerX) * (x - centerX)) / (a * a) + ((y - centerY) * (y - centerY)) / (b * b) + ((z - centerZ) * (z - centerZ)) / (c * c) <= 1;
}
const idwAnisotropicSearch = (x, y, z, inputData, num, power = 2, a, b, c) => {
let sum = 0;
let weights = 0;
let distances = []
for (let i = 0; i < inputData.length; i++) {
const xi = inputData[i][0];
const yi = inputData[i][1];
const zi = inputData[i][2];
const ai = inputData[i][3];
//先搜索矩形
if (xi > x - a && x < x + a && yi > y - a && yi < y + b && zi > z - c && zi < z + c) {
//再判断是否在椭圆内部
if (isEllipsoidInside(xi, yi, zi, x, y, z, a, b, c)) {
const distance = Math.sqrt((xi - x) ** 2 + (yi - y) ** 2 + (zi - z) ** 2);
if (distance === 0) return ai
distances.push({distance, value: ai})
}
}
if (!distances.length) return 0
}
distances.sort((a, b) => a.distance - b.distance);
for (let i = 0; i < num; i++) {
const distance = distances[i].distance;
const weight = 1 / distance ** power;
sum += weight * distances[i].value;
weights += weight;
}
return sum / weights
}
基于三维点的idw各向异性插值
最新推荐文章于 2024-08-22 14:32:34 发布