/// <summary> /// Determines the locations (from a given list of locations) that are closest to the given target. /// </summary> /// <param name="targetLatitude">The target's latitude.</param> /// <param name="targetLongitude">The target's longitude.</param> /// <param name="targetAltitude">The target's altitude (ASL).</param> /// <param name="places">The population of locations to choose from.</param> /// <returns> /// An array of locations (one for each possible facility upgrade level) that are closest to /// the target coordinates. /// </returns> internal Locale[] FindClosest(double targetLatitude, double targetLongitude, double targetAltitude) { var closestLocale = new Locale[] { new Locale { }, new Locale { Distance = double.MaxValue }, new Locale { Distance = double.MaxValue }, new Locale { Distance = double.MaxValue } }; var startpoint = new WorldCoordinates() { Latitude = targetLatitude, Longitude = targetLongitude, Altitude = targetAltitude, World = Homeworld, }; foreach (var location in _allLocations) { var gc = new GreatCircle(startpoint, location.Coordinates); for (int level = 1; level < 4; level++) { var facilityLevel = (FacilityLevels)(int)Math.Pow(2, level - 1); var locationIsAvailable = ((location.AvailableAtLevels & facilityLevel) != FacilityLevels.None); if (locationIsAvailable && (gc.DistanceWithAltChange < closestLocale[level].Distance)) { closestLocale[level] = new Locale { Name = location.LocationName, Horizontal = gc.DistanceAtDestAlt, Vertical = gc.DeltaASL, Distance = gc.DistanceWithAltChange, }; } } } return(closestLocale); }
public Centrum() { Coordinates = WorldCoordinates.GetFacilityCoordinates <FlagPoleFacility>(); $" KSC flag = lat:{Coordinates.Latitude} long:{Coordinates.Longitude} alt:{Coordinates.Altitude} radius:{Coordinates.WorldRadius}".Debug(); var VABPosition = WorldCoordinates.GetFacilityCoordinates <VehicleAssemblyBuilding>(); $"VAB = lat:{VABPosition.Latitude} long:{VABPosition.Longitude} alt:{VABPosition.Altitude}".Debug(); var route = new GreatCircle(Coordinates, VABPosition); $"Route from Flag to VAB = bearing:{route.ForwardAzimuth} dist:{route.DistanceAtOrigAlt} alt:{route.DeltaASL}".Debug(); AngularOffset = Math.Round(route.ForwardAzimuth - BaseBearingFlagToVAB, RoundingAccuracy, MidpointRounding.AwayFromZero); HorizontalScale = Math.Round(route.DistanceAtOrigAlt / BaseDistanceFlagToVAB, RoundingAccuracy, MidpointRounding.AwayFromZero); VerticalScale = Math.Round(route.DeltaASL / BaseDeltaAltFlagToVAB, RoundingAccuracy, MidpointRounding.AwayFromZero); $"Offset:{AngularOffset} degrees, Scaling:{HorizontalScale}(h) x {VerticalScale}(v)".Debug(); }
/// <summary> /// Creates a location based on the supplied user information and the currently active vessel. /// </summary> /// <param name="request">The user's requested location information.</param> /// <returns>A new location.</returns> private static Location CreateRequestedLocation(LocationRequest request) { var requestCoordinates = new WorldCoordinates( Homeworld, FlightGlobals.ActiveVessel.latitude, FlightGlobals.ActiveVessel.longitude, FlightGlobals.ActiveVessel.altitude); var displacement = new GreatCircle(GetCentrum().Coordinates, requestCoordinates); return(new Location { LocationName = request.Name, FacilityName = request.AssociatedFacility, AvailableAtLevels = GetFacilityLevel(request.AssociatedFacility), Queueing = 0, ForwardAzimuth = displacement.ForwardAzimuth - GetCentrum().AngularOffset, Distance = displacement.DistanceAtOrigAlt / GetCentrum().HorizontalScale, DeltaAltitude = displacement.DeltaASL / GetCentrum().VerticalScale, Normal = FlightGlobals.ActiveVessel.terrainNormal, Rotation = FlightGlobals.ActiveVessel.transform.rotation, }); }
public WorldCoordinates Travel(GreatCircle route) { return(Add(route.ForwardAzimuth, route.DistanceAtOrigAlt, route.DeltaASL)); }