已知起点经纬度及两点间距离、方位角如何求出终点经纬度?(附C#与python代码)

Get lat/long given current point, distance and bearing.

1、计算公式:
lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))
lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))
其中,

  • asin = arc sin()

  • d = distance (in any unit)

  • R = Radius of the earth (in the same unit as above)

and hence d/r = is the angular distance (in radians)

  • atan2(a,b) = arc tan(b/a)
  • θ is the bearing (in radians, clockwise from north);

2、C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{

    class Program
    {
        static void Main(string[] args)
        {    
            const double radiusEarthKilometres = 6371.01f; //地球半径,以km为单位
            double lat0 = -42.3993; //起点的纬度
            double lon0 = 172.7393; //起点的经度
            double kmDistance =76; //两点间的距离
            double angleRadHeading = 248.352;  //方位角:以正北为起始方向顺时针
            angleRadHeading =angleRadHeading/180 * Math.PI;
            double newLat = 0;
            double newLong = 0;

            var distRatio = kmDistance / radiusEarthKilometres;
            var distRatioSine = Math.Sin(distRatio);
            var distRatioCosine = Math.Cos(distRatio);

            var startLatRad = lat0/180*Math.PI;
            var startLonRad = lon0 / 180 * Math.PI;

            var startLatCos = Math.Cos(startLatRad);
            var startLatSin = Math.Sin(startLatRad);

            var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(angleRadHeading)));

            var endLonRads = startLonRad
                + Math.Atan2(Math.Sin(angleRadHeading) * distRatioSine * startLatCos,
                    distRatioCosine - startLatSin * Math.Sin(endLatRads));

            newLat = endLatRads/Math.PI*180;
            newLong = endLonRads / Math.PI * 180;
            Console.WriteLine("终点的纬度为:{0}", newLat.ToString());
            Console.WriteLine("终点的经度为:{0}", newLong.ToString());
            Console.ReadLine();
        }
    }
}

3、python代码:

import math

R = 6378.1 #Radius of the Earth
brng = 1.57 #Bearing is 90 degrees converted to radians.
d = 15 #Distance in km

#lat2  52.20444 - the lat result I'm hoping for
#lon2  0.36056 - the long result I'm hoping for.

lat1 = math.radians(52.20472) #Current lat point converted to radians
lon1 = math.radians(0.14056) #Current long point converted to radians

lat2 = math.asin( math.sin(lat1)*math.cos(d/R) +
     math.cos(lat1)*math.sin(d/R)*math.cos(brng))

lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
             math.cos(d/R)-math.sin(lat1)*math.sin(lat2))

lat2 = math.degrees(lat2)
lon2 = math.degrees(lon2)

print(lat2)
print(lon2)

4、参考:

  • https://stackoverflow.com/questions/7222382/get-lat-long-given-current-point-distance-and-bearing
  • https://cloud.tencent.com/developer/ask/152388

你可能感兴趣的:(Geodesy,and,Geomatics)