Calculate endpoint given distance, bearing, starting point

后端 未结 4 670
自闭症患者
自闭症患者 2020-12-06 11:38

I am trying to find the destination point, given a starting point lat/long, bearing & distance. The calculator from this website below gives me the desired results.

4条回答
  •  生来不讨喜
    2020-12-06 12:01

    Here is my code that I converted to C# from http://www.movable-type.co.uk/scripts/latlong.html. It should be pretty simple to use.

    public static (double Lat, double Lon) Destination((double Lat, double Lon) startPoint, double distance, double bearing)
        {
            double lat1 = startPoint.Lat * (Math.PI / 180);
            double lon1 = startPoint.Lon * (Math.PI / 180);
            double brng = bearing * (Math.PI / 180);
            double lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(distance / radius) + Math.Cos(lat1) * Math.Sin(distance / radius) * Math.Cos(brng));
            double lon2 = lon1 + Math.Atan2(Math.Sin(brng) * Math.Sin(distance / radius) * Math.Cos(lat1), Math.Cos(distance / radius) - Math.Sin(lat1) * Math.Sin(lat2));
            return (lat2 * (180 / Math.PI), lon2 * (180 / Math.PI));
        }
    

    radius is a constant for the Earth's radius in meters.

    It uses tuples so you can access the latitude or longitude individually with .Lat or .Lon.

提交回复
热议问题