10
我有Lat Long格式的2個座標。C中2個緯度/經度點之間的方向#
如何從A點(如紐約37.149472,-95.509544)確定度到B點(如多倫多40.714269,-74.005973)方向
我正在尋找像「340度的值「
在C#中,如果你看看
我有Lat Long格式的2個座標。C中2個緯度/經度點之間的方向#
如何從A點(如紐約37.149472,-95.509544)確定度到B點(如多倫多40.714269,-74.005973)方向
我正在尋找像「340度的值「
在C#中,如果你看看
如果你想有一個恆定的軸承跟着你不想你想要一個恆向線爲
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);
在http://www.movable-type.co.uk/scripts/latlong.html它的JavaScript可以改寫爲C#。
最後
轉換Movable Type的腳本的最短(大圈)路徑,使用System.Math的好理由。 當然,很多人每天都在做,但它真的從來沒有出現過。謝謝。 – tsilb 2010-08-19 15:22:22