在C#2纬度/经度点之间方向 [英] Direction between 2 Latitude/Longitude points in C#
本文介绍了在C#2纬度/经度点之间方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在纬度长格式的2坐标。
I have 2 coordinates in Lat Long format.
我如何从A点(如纽约37.149472,-95.509544)以度到B点的方向确定(如多伦多40.714269,-74.005973)
How do I determine from Point A (eg New York 37.149472,-95.509544 ) the direction in degrees to point B (eg Toronto 40.714269,-74.005973)
我正在寻找像340度
值在C#
推荐答案
如果你想有一个恒定的轴承跟着你不想让你想在最短的(大圈)路径恒向线
If you want a constant bearing to follow you don't want the shortest (great circle) path you want a Rhumb line
Movable Type的脚本为
Conversion of the Movable Type Scripts for that
static double DegreeBearing(
double lat1, double lon1,
double lat2, double lon2)
{
var dLon = ToRad(lon2-lon1);
var dPhi = Math.Log(
Math.Tan(ToRad(lat2)/2+Math.PI/4)/Math.Tan(ToRad(lat1)/2+Math.PI/4));
if (Math.Abs(dLon) > Math.PI)
dLon = dLon > 0 ? -(2*Math.PI-dLon) : (2*Math.PI+dLon);
return ToBearing(Math.Atan2(dLon, dPhi));
}
public static double ToRad(double degrees)
{
return degrees * (Math.PI / 180);
}
public static double ToDegrees(double radians)
{
return radians * 180 / Math.PI;
}
public static double ToBearing(double radians)
{
// convert radians to degrees (as bearing: 0...360)
return (ToDegrees(radians) +360) % 360;
}
// verify against the website example
DegreeBearing(50.36389,-4.15694,42.35111,-71.04083);
这篇关于在C#2纬度/经度点之间方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文