【问题标题】:Direction based off of 2 Lat,Long points基于 2 个纬度、经度点的方向
【发布时间】:2012-12-18 20:55:29
【问题描述】:

我正在寻找一个可以发送 2 Lat, Longs 的函数。 1 Lat, long 是我的基础,第二个是我想确定它是 N、S、E 还是 West。还是我必须去 NW,N,NE,EN,E,ES,SE,S,SW,WS,W,WN?无论哪种方式,有人在 C# 中有这样的东西吗?

【问题讨论】:

    标签: c# google-maps latitude-longitude computational-geometry google-earth


    【解决方案1】:

    首先你可以计算大圆方位

    θ = atan2( sin(Δλ).cos(φ2), cos(φ1).sin(φ2) - sin(φ1).cos(φ2).cos(Δλ) )

    JavaScript(可轻松转换为 C#):

    var y = Math.sin(dLon) * Math.cos(lat2);
    var x = Math.cos(lat1)*Math.sin(lat2) -
            Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
    var brng = Math.atan2(y, x).toDeg();
    

    http://www.movable-type.co.uk/scripts/latlong.html

    然后将结果分割成所需的基本方向,例如如果方位在 -45(315 度)度和 45 度之间,则为北,依此类推。

    public string Cardinal(double degrees)
    {
        if (degrees > 315.0 || degrees < 45.0)
        {
            return "N";
        }
        else if (degrees >= 45.0 && degrees < 90)
        {
            return "E";
        }
        // Etc for the whole 360 degrees.  Segment finer if you want NW, WNW, etc.
    }
    

    【讨论】:

    • 我是不是假设计算大方位圆的灰色线只是函数而不是代码?
    • @StephanM:如果 灰色线条 你的意思是带有希腊符号的那个,是的。我用代码更新了答案。
    • dLon 从何而来?
    • @StephanM:dLon 是以度为单位的经度。
    猜你喜欢
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多