如何在 JavaScript 中获得真正随机均匀的 GPS 坐标分布?
How can I get truly random even distribution of GPS coordinates in JavaScript?
我的第一次尝试产生的点通常靠近极地地区:
gps = {
lat: (Math.random() * (90 - -90) + -90) * Math.PI / 180,
lon: (Math.random() * (180 - -180) + -180) * Math.PI / 180,
alt: 0
};
(是的,我正在转换为弧度)
我很快意识到这是一个不均匀的分布。
根据这个网站 https://dosull.github.io/posts/2021-10-20-random-even-points-on-the-globe/ I'll need to use some sort of "acos" (is that arccos?) function, but I don't even know what language that is. whuber's comment at https://gis.stackexchange.com/questions/236321/generating-random-lat-long-coordinates 提到 cosine 但我不确定公式到底是什么。
lat: Math.acos(Math.random() * 2 - 1) - Math.PI / 2,
我的第一次尝试产生的点通常靠近极地地区:
gps = {
lat: (Math.random() * (90 - -90) + -90) * Math.PI / 180,
lon: (Math.random() * (180 - -180) + -180) * Math.PI / 180,
alt: 0
};
(是的,我正在转换为弧度) 我很快意识到这是一个不均匀的分布。 根据这个网站 https://dosull.github.io/posts/2021-10-20-random-even-points-on-the-globe/ I'll need to use some sort of "acos" (is that arccos?) function, but I don't even know what language that is. whuber's comment at https://gis.stackexchange.com/questions/236321/generating-random-lat-long-coordinates 提到 cosine 但我不确定公式到底是什么。
lat: Math.acos(Math.random() * 2 - 1) - Math.PI / 2,