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 ToDegreesNormalized(double radians) { double degrees = WorldUtils.ToDegrees(radians); degrees = (degrees + 360) % 360; return(degrees); }