使用圆量的加权插值

问题描述 投票:1回答:1

我正在加权加权内插项目。每个站点在地图上都有一个坐标点,如下所示。

var stationCoor = [[408,352],[525,348],[535,495],[420,400],[272,145],[175,195],[197,335]];

我正在获取位于湖中的点,并正在使用这些点为来自这些站的输入创建加权平均值。这是我确定加权数字的功能。

function findWeightSpeed(xPos, yPos){
   var totalHypt = 0;
   var arrHpyt = [];
   var arrWeight = [];
   for(var l=0;l<7;l++){
       var xDis = Math.abs(xPos-stationCoor[l][0]);
       var yDis = Math.abs(yPos-stationCoor[l][1]);
       var hptSq = Math.pow(xDis,2)+Math.pow(yDis,2);
       var hypt = Math.sqrt(hptSq);
       totalHypt = totalHypt+hypt;
       arrHpyt.push(hypt);
   }
   for(var j=0;j<7;j++){
       arrWeight.push(arrHpyt[j]/totalHypt)
   }
   return arrWeight;
}

这将找到点(xPos,yPos)与测站之间的斜边。然后将数据相加,然后将每个站点除以总和,得出加权数字。

我需要使用这些点来加权这些站的风向。我正在使用下面的功能来计算平均分。

function averageAngles(){
    var x = 0;
    var y = 0;
    var pi = 22/7;
    var angle = [2.7925,2.8797,2.9670,3.0543, 0.0872]; // 310,320,330,340,10
    for(var i = 0; i < angle.length; i++) {
        x += Math.cos(angle[i]);
        y += Math.sin(angle[i]);
    }
    var average_angle = Math.atan2(y, x);
    console.log((average_angle/pi)*360);
}

这为我提供了准确的信息,所有点的加权平均值为.20。但是,这7个站点的加权平均点(如下面的地图所示)类似于[0.1076839005418769, 0.08051796093187284, 0.003987308213631277, 0.08458358029618485, 0.2463427297217639, 0.26463834002675196, 0.21224618026791833]

我将如何创建一个从findWeightSpeed()中获取加权平均值并使用其对averageAngles()中的循环量加权的函数?

我使用此How do you calculate the average of a set of circular data?进行平均角度的功能。

非常感谢您提供的任何建议。

Image of Clear Lake Map

javascript math interpolation weighted-average
1个回答
0
投票

这里是我在网上找到的链接,它解释了整个过程。

Computing Weighted Averages for Wind Speed and Direction

代码与此相似。

function weightAllData(xPos,yPos,windData){
                var uVecSum = 0;
                var vVecSum = 0;
                var arrayWeightSpeed = findWeightSpeed(xPos, yPos); //using weighted interpolation based on distance
                var arrayWindSpeed = [WSData];
                var arrayWindDirection = [WDData];
                for(var m=0;m<7;m++){
                    uVecSum = uVecSum + (arrayWeightSpeed[m] * getUVector(arrayWindSpeed[m],(arrayWindDirection[m]/180)*Math.PI));
                    vVecSum = vVecSum + (arrayWeightSpeed[m] * getVVector(arrayWindSpeed[m],(arrayWindDirection[m]/180)*Math.PI));
                }

                var weightWS = Math.sqrt(Math.pow(uVecSum,2)+Math.pow(vVecSum,2));
                if(vVecSum!=0){
                    weightWDRad = Math.atan(uVecSum/vVecSum);
                }
                if(vVecSum==0){
                    weightWDRad = Math.atan(uVecSum/(0.0001+vVecSum));
                }
                if(weightWDRad<0){
                    weightWDRad = weightWDRad + Math.PI
                }
                weightWD = (weightWDRad * (180/Math.PI));
}

让我知道是否要解释

© www.soinside.com 2019 - 2024. All rights reserved.