尝试从起点计算经纬度给定距离和方位
Attempting to calculate lat and long given distance and bearing from start point
使用 this 网站我试图从初始纬度和经度以及 C# 中的距离和方位角计算纬度和经度,但我无法使其正常工作。无论方位和距离如何,输出似乎总是或多或少地与起点垂直地贴在赤道附近。我已经按照网站上说的做了,但没有成功。
这是我到目前为止所做的:
public static double[] LocWithBearingAndDistance(double lat, double lon, double bearing, double distanceM)
{
double angdistance = distanceM / 6371000.0;
double lat2 = Math.Asin(Math.Sin(lat) * Math.Cos(angdistance) + Math.Cos(lat) * Math.Sin(angdistance) * Math.Cos(bearing));
double lon2 = lon + Math.Atan2(Math.Cos(angdistance) - Math.Sin(lat) * Math.Sin(lat2), Math.Sin(bearing) * Math.Sin(angdistance) * Math.Cos(lat));
return new double[2] {lat2, (lon2 + 540) % 360 - 180};
}
感谢您的帮助。
这是我解决问题的代码:
public static (double Lat, double Lon) Destination((double Lat, double Lon) startPoint, double distance, double bearing)
{
double φ1 = startPoint.Lat * (Math.PI / 180);
double λ1 = startPoint.Lon * (Math.PI / 180);
double brng = bearing * (Math.PI / 180);
double φ2 = Math.Asin(Math.Sin(φ1) * Math.Cos(distance / radius) + Math.Cos(φ1) * Math.Sin(distance / radius) * Math.Cos(brng));
double λ2 = λ1 + Math.Atan2(Math.Sin(brng) * Math.Sin(distance / radius) * Math.Cos(φ1), Math.Cos(distance / radius) - Math.Sin(φ1) * Math.Sin(φ2));
return (φ2 * (180 / Math.PI), λ2 * (180 / Math.PI));
}
radius
是以米为单位的地球半径。
使用 this 网站我试图从初始纬度和经度以及 C# 中的距离和方位角计算纬度和经度,但我无法使其正常工作。无论方位和距离如何,输出似乎总是或多或少地与起点垂直地贴在赤道附近。我已经按照网站上说的做了,但没有成功。
这是我到目前为止所做的:
public static double[] LocWithBearingAndDistance(double lat, double lon, double bearing, double distanceM)
{
double angdistance = distanceM / 6371000.0;
double lat2 = Math.Asin(Math.Sin(lat) * Math.Cos(angdistance) + Math.Cos(lat) * Math.Sin(angdistance) * Math.Cos(bearing));
double lon2 = lon + Math.Atan2(Math.Cos(angdistance) - Math.Sin(lat) * Math.Sin(lat2), Math.Sin(bearing) * Math.Sin(angdistance) * Math.Cos(lat));
return new double[2] {lat2, (lon2 + 540) % 360 - 180};
}
感谢您的帮助。
这是我解决问题的代码:
public static (double Lat, double Lon) Destination((double Lat, double Lon) startPoint, double distance, double bearing)
{
double φ1 = startPoint.Lat * (Math.PI / 180);
double λ1 = startPoint.Lon * (Math.PI / 180);
double brng = bearing * (Math.PI / 180);
double φ2 = Math.Asin(Math.Sin(φ1) * Math.Cos(distance / radius) + Math.Cos(φ1) * Math.Sin(distance / radius) * Math.Cos(brng));
double λ2 = λ1 + Math.Atan2(Math.Sin(brng) * Math.Sin(distance / radius) * Math.Cos(φ1), Math.Cos(distance / radius) - Math.Sin(φ1) * Math.Sin(φ2));
return (φ2 * (180 / Math.PI), λ2 * (180 / Math.PI));
}
radius
是以米为单位的地球半径。