开发者

Weighted random bearing for wandering point

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

Here is my very basic wandering point. It create开发者_运维知识库s a geospatial point then moves one metre in a random direction every second. However, this is too random. How can I give my wandering point some direction so that it actually moves somewhere? Are the any good examples out there of a wandering geospatial point?


You could store last wandering coefficient (as I undestand that would be randomBetween(...) value) in a variable, and next time use a weighted average of this value and new random value.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜