public static GeoLocation CalcDestination(GeoLocation origin, double bearing, double distance) { double radius = 6371.0; origin = WorldUtils.ToRadianLocation(origin); bearing = WorldUtils.ToRadians(bearing); distance = distance / radius; double lat = Math.Asin(Math.Sin(origin.Lat) * Math.Cos(distance) + Math.Cos(origin.Lat) * Math.Sin(distance) * Math.Cos(bearing)); double x = Math.Sin(bearing) * Math.Sin(distance) * Math.Cos(origin.Lat); double y = Math.Cos(distance) - Math.Sin(origin.Lat) * Math.Sin(origin.Lat); double lon = origin.Lon + Math.Atan2(x, y); // normalize lon to coordinate between -180º and +180º lon = (lon + 3 * Math.PI) % (2 * Math.PI) - Math.PI; lon = WorldUtils.ToDegrees(lon); lat = WorldUtils.ToDegrees(lat); return(new GeoLocation() { Lat = lat, Lon = lon }); }
public static double CalcBearing(GeoLocation origin, GeoLocation dest) { origin = WorldUtils.ToRadianLocation(origin); dest = WorldUtils.ToRadianLocation(dest); double range = (dest.Lon - origin.Lon); double y = Math.Sin(range) * Math.Cos(dest.Lat); double x = Math.Cos(origin.Lat) * Math.Sin(dest.Lat) - Math.Sin(origin.Lat) * Math.Cos(dest.Lat) * Math.Cos(range); double angle = Math.Atan2(y, x); return(WorldUtils.ToDegreesNormalized(angle)); }
public static double CalcDistance(GeoLocation origin, GeoLocation dest) { origin = WorldUtils.ToRadianLocation(origin); dest = WorldUtils.ToRadianLocation(dest); double sinProd = Math.Sin(origin.Lat) * Math.Sin(dest.Lat); double cosProd = Math.Cos(origin.Lat) * Math.Cos(dest.Lat); double lonDelta = (dest.Lon - origin.Lon); double angle = Math.Acos(sinProd + cosProd * Math.Cos(lonDelta)); double distance = angle * 6371.0; return(distance); }