/// <summary> /// Calculate the azimuth in degrees between two locators /// </summary> /// <param name="A">Start LatLng structure</param> /// <param name="B">End LatLng structure</param> /// <returns>Azimuth in degrees</returns> public static double Azimuth(LatLng A, LatLng B) { if (A.CompareTo(B) == 0) { return(0); } double hn = DegToRad(A.Lat); double he = DegToRad(A.Long); double n = DegToRad(B.Lat); double e = DegToRad(B.Long); double co = Math.Cos(he - e) * Math.Cos(hn) * Math.Cos(n) + Math.Sin(hn) * Math.Sin(n); double ca = Math.Atan(Math.Abs(Math.Sqrt(1 - co * co) / co)); if (co < 0) { ca = Math.PI - ca; } double si = Math.Sin(e - he) * Math.Cos(n) * Math.Cos(hn); co = Math.Sin(n) - Math.Sin(hn) * Math.Cos(ca); double az = Math.Atan(Math.Abs(si / co)); if (co < 0) { az = Math.PI - az; } if (si < 0) { az = -az; } if (az < 0) { az = az + 2 * Math.PI; } return(RadToDeg(az)); }
/// <summary> /// Calculate the distance in km between two locators /// </summary> /// <param name="A">Start LatLng structure</param> /// <param name="B">End LatLng structure</param> /// <returns>Distance in km</returns> public static double Distance(LatLng A, LatLng B) { if (A.CompareTo(B) == 0) { return(0); } double hn = DegToRad(A.Lat); double he = DegToRad(A.Long); double n = DegToRad(B.Lat); double e = DegToRad(B.Long); double co = Math.Cos(he - e) * Math.Cos(hn) * Math.Cos(n) + Math.Sin(hn) * Math.Sin(n); double ca = Math.Atan(Math.Abs(Math.Sqrt(1 - co * co) / co)); if (co < 0) { ca = Math.PI - ca; } double dx = 6367 * ca; return(dx); }