Code: Select all
public static double AngleBetweenLocations(double Lat1Degrees,
double Lon1Degrees,
double Lat2Degrees,
double Lon2Degrees)
{
double Lat1Radians = Radians(Lat1Degrees);
double Lon1Radians = Radians(Lon1Degrees);
double Lat2Radians = Radians(Lat2Degrees);
double Lon2Radians = Radians(Lon2Degrees);
double a = Lon1Radians - Lon2Radians;
if (a < 0.0)
{
a = -a;
}
if (a > Math.PI)
{
a = 2.0 * Math.PI - a;
}
return Math.Acos(
Math.Sin(Lat2Radians) * Math.Sin(Lat1Radians) +
Math.Cos(Lat2Radians) * Math.Cos(Lat1Radians) * Math.Cos(a)
);
}
public static double Radians(double degrees)
{
return degrees * Math.PI / 180.0;
}