从距离中心

时间:2017-06-24 19:17:19

标签: javascript math geolocation maps leaflet

我在地图中有一个给定的中心[x1,y1]。从那个中心我画了一个半径为1英里的圆圈。我需要在圆圈周围生成8个以上的点,各个点到中心之间的距离应该是1英里,所以它们在圆圈边界上。我知道得到x2,y2的公式,但问题是它不适用于地球的地图,因为它不是一个完美的球体。

我已尝试使用this,但没有运气。

有人能指点我或者说我错了吗?

编辑:已解决!

因此,仔细阅读整个Movable Type Scripts,我发现了这个(稍微修改了一下):

   let getPoint = (distance, bearing, center) => {

    let δ = Number(distance) / 6371e3; 
    let θ = Number(bearing).toRadians();

    let φ1 = center[0].toRadians();
    let λ1 = center[1].toRadians();

    let sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1);
    let sinδ = Math.sin(δ), cosδ = Math.cos(δ);
    let sinθ = Math.sin(θ), cosθ = Math.cos(θ);

    let sinφ2 = sinφ1*cosδ + cosφ1*sinδ*cosθ;
    let φ2 = Math.asin(sinφ2);
    let y = sinθ * sinδ * cosφ1;
    let x = cosδ - sinφ1 * sinφ2;
    let λ2 = λ1 + Math.atan2(y, x);

    return [φ2.toDegrees(), (λ2.toDegrees()+540)%360-180]; 
};

它确实解决了我的问题。

1 个答案:

答案 0 :(得分:2)

您正在尝试解决所谓的first (or direct) geodetic problem。知道这个名字将使您的研究更容易。

正如#34; How to draw polyline perpendicular to another polyline using Leaflet"的回答所指出的那样。和#34; Find destination coordinates given starting coodinates, bearing, and distance",您在javascript中解决此问题的主要选项是cheap-ruler用于小(ish)区域和greographiclib用于远距离。

廉价标尺往往非常快但不准确,而且地理位置往往较慢但非常准确。

您可能会发现其他实现,每个实现都有自己的妥协。大地测量很难,所以there is no "one true way"来计算距离或方位角。

相关问题