方向基于2 Lat,Long points [英] Direction based off of 2 Lat,Long points

查看:120
本文介绍了方向基于2 Lat,Long points的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个可以发送2个经纬度的函数。 1拉特,长是我的基础,第二个是我想确定它是N,S,E还是西。或者我是否必须去NW,N,NE,EN,E,ES,SE,S,SW,WS,W,WN?无论哪种方式在C#中都没有类似的东西?

解决方案

首先,您可以计算大圆圈方位


$ b


θ= 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度之间,则为北等。

 公共字符串Cardinal(double度数)
{
if(度数> 315.0 ||度数< 45.0)
{
returnN;
}
else if(度数> = 45.0&& degree <90)
{
返回E;
}
//等整个360度。细分市场,如果你想NW,WNW等


I am looking for a function that will allow me to send 2 Lat, Longs. 1 Lat, long is my base and the second is what I want to determine if it is N,S,E, or West. Or would I have to go NW,N,NE,EN,E,ES,SE,S,SW,WS,W,WN? Either way does anyone have something like this in C#?

解决方案

First you can calculate the Great Circle Bearing

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

JavaScript (easily convertable to 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

Then segment the result into the desired cardinal directions, e.g. if bearing is between -45 (315 degrees) degrees and 45 degrees it is North and so on.

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.
}

这篇关于方向基于2 Lat,Long points的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆