Created
June 18, 2020 03:13
-
-
Save BicycleMark/3e1a2152febaa2935e4c8cfcea7e061b to your computer and use it in GitHub Desktop.
GetPointByDistanceAndHeading(double fmLat, double fmLon, double heading, double distanceKm)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Text; | |
namespace MobileIE.Classes | |
{ | |
public class GeoMath | |
{ | |
public static readonly double EarthRadius = 6378.1; //#Radius of the Earth km | |
public Tuple<double,double> GetPointByDistanceAndHeading(double fmLat, double fmLon, double heading, double distanceKm) | |
{ | |
double bearingR = heading.ToRadians(); | |
double latR = fmLat.ToRadians(); | |
double lonR = fmLon.ToRadians(); | |
double distanceToRadius = distanceKm / EarthRadius; | |
double newLatR = Math.Asin(Math.Sin(latR) * Math.Cos(distanceToRadius) | |
+ Math.Cos(latR) * Math.Sin(distanceToRadius) * Math.Cos(bearingR)); | |
double newLonR = lonR + Math.Atan2( | |
Math.Sin(bearingR) * Math.Sin(distanceToRadius) * Math.Cos(latR), | |
Math.Cos(distanceToRadius) - Math.Sin(latR) * Math.Sin(newLatR) | |
); | |
return new Tuple<double, double>(newLatR.ToDegrees(), newLonR.ToDegrees()); | |
} | |
} | |
public static class NumericExtensions | |
{ | |
public static double ToRadians(this double degrees) | |
{ | |
return (Math.PI / 180) * degrees; | |
} | |
public static double ToDegrees(this double radians) | |
{ | |
return (180 / Math.PI) * radians; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment