漫游点的加权随机轴承

时间:2011-06-02 09:35:39

标签: javascript random geospatial

var latlon = new LatLon(50,-0.075);
setInterval(function(){
    latlon = latlon.destinationPoint(randomBetween(0,360),0.001);
},1000);

这是我非常基本的徘徊点。它创建一个地理空间点,然后每秒随机移动一米。但是,这太随机了。我怎样才能让我的徘徊点向某个方向移动,以便它实际移动到某个地方?是否存在一个流浪的地理空间点的好例子?

1 个答案:

答案 0 :(得分:0)

您可以在变量中存储最后的游走系数(我理解为randomBetween(...)值),然后使用此值和新随机值的加权平均值。

var latlon = new LatLon(50,-0.075);
var oldValue = randomBetween(0,360);
var weights = [0.5, 0.5];  // Here you can influece the level of 'randomness'. 
// Just make sure to weights sum up to 1
setInterval(function(){
    var newValue = oldValue * weights[0] + randomBetween(0,360) * weights[1];
    latlon = latlon.destinationPoint(newValue, 0.001);
    oldValue = newValue;
},1000);