JavaScript: Getting random location on globe -


i trying create function returns random point on globe. when try following code, ends bunching more of points @ poles , fewer @ equator.

function random_location() {   return {     lon: math.floor(math.random() * 360) - 179,     lat: math.floor(math.random() * 181) - 90   } }  (var = 0; < 100; i++) {   var location = random_location();   // } 

how should this?

note: point might on sphere size of earth, other size. need create randomly evenly distributed latitude , longitude.

from http://mathworld.wolfram.com/spherepointpicking.html :

function random_location() {   return {     lon: math.floor(math.random()*360) - 180,     lat: math.round(math.acos(2*math.random() - 1)*180/math.pi) - 90   } } 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -