private static ConfigNode ThisGravityMap(string Body) { ConfigNode returnNode = new ConfigNode("GRAVITYMAP"); foreach (ConfigNode GravityMap in GMSData.GetNodes("GRAVITYMAP")) { if (GravityMap.GetValue("body") == Body) { returnNode = GravityMap; break; } } return(returnNode); }
public static double GalAtPosition(Vessel vessel) { GravityMap LocalMap = ThisGravityMap(vessel.orbitDriver.orbit.referenceBody.GetName()); double meanGal = LocalMap.meanGal; Mascon MasCon = LocalMasCon(vessel); double CentreGal = MasCon.centreGal; double CentreLat = MasCon.centreLat; double CentreLong = MasCon.centreLong; double radiusdeg = MasCon.diamdeg / 2; double EdgeLat = CentreLat + radiusdeg; double EdgeLong = CentreLong + radiusdeg; double GalAtDistance = 0.0; double R = vessel.orbitDriver.orbit.referenceBody.Radius; double A = ToRadians(CentreLat); double B = ToRadians(EdgeLat); double C = ToRadians(EdgeLat) - ToRadians(CentreLat); double D = ToRadians(EdgeLong) - ToRadians(CentreLong); double E = Math.Sin(C / 2) * Math.Sin(C / 2) + Math.Cos(A) * Math.Cos(B) * Math.Sin(D / 2) * Math.Sin(D / 2); double F = 2 * Math.Atan2(Math.Sqrt(E), Math.Sqrt(1 - E)); double Edgedistance = R * F; double φ1 = ToRadians(CentreLat); double φ2 = ToRadians(vessel.latitude); double Δφ = ToRadians(vessel.latitude) - ToRadians(CentreLat); double Δλ = ToRadians(vessel.longitude) - ToRadians(CentreLong); double a = Math.Sin(Δφ / 2) * Math.Sin(Δφ / 2) + Math.Cos(φ1) * Math.Cos(φ2) * Math.Sin(Δλ / 2) * Math.Sin(Δλ / 2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double Vesseldistance = R * c; GalAtDistance = Math.Abs(CentreGal) / Edgedistance * Vesseldistance; // Work out negative push mascons for 1.6.0 removed absolute CentreGal /* * double GravitationalConstant = 6.67408 * Math.Pow(10.0, -11.0); // G [Newton Meter Squared per Square Kilograms] * double AccelerationToGal = 100.0; * double GalAtSurface = ((GravitationalConstant * vessel.orbitDriver.orbit.referenceBody.Mass * vessel.GetCorrectVesselMass())); * double GalAtVerticalDistance = ((GravitationalConstant * vessel.orbitDriver.orbit.referenceBody.Mass * vessel.GetCorrectVesselMass()) / (Math.Pow(vessel.orbitDriver.orbit.altitude,2.0))) * AccelerationToGal; * GalAtDistance = GalAtDistance + GalAtVerticalDistance; */ return(GalAtDistance); }
public static void LoadData() { //GMSData = ConfigNode.Load(MasConDataFilePath); if (gravityMapDict == null) { MasConDataFilePath = KSPUtil.ApplicationRootPath + "GameData/WhitecatIndustries/OrbitalDecay/PluginData/MasConData.cfg"; gravityMapDict = new Dictionary <string, GravityMap>(); var node = ConfigNode.Load(MasConDataFilePath); foreach (var n in node.GetNodes("GRAVITYMAP")) { GravityMap gm = new GravityMap(n); gravityMapDict.Add(gm.body, gm); } } }
private static GravityMap ThisGravityMap(string Body) { if (gravityMapDict.ContainsKey(Body)) { return(gravityMapDict[Body]); } else { return(null); } #if false ConfigNode returnNode = new ConfigNode("GRAVITYMAP"); foreach (ConfigNode GravityMap in GMSData.GetNodes("GRAVITYMAP")) { if (GravityMap.GetValue("body") == Body) { returnNode = GravityMap; break; } } return(returnNode); #endif }
public static bool CheckMasConProximity(Vessel vessel) { bool WithinEffectRange = false; if (vessel.orbitDriver.orbit.referenceBody.GetName() == "Earth" || vessel.orbitDriver.orbit.referenceBody.GetName() == "Kerbin" || vessel.orbitDriver.orbit.referenceBody.GetName() == "Moon") // { GravityMap LocalGravityMap = ThisGravityMap(vessel.orbitDriver.orbit.referenceBody.GetName()); if (LocalGravityMap.masconAr.Count() > 0) { double VesselLat = vessel.latitude; double VesselLong = vessel.longitude; bool LatitudeWithin = false; bool LongitudeWithin = false; foreach (var MasCon in LocalGravityMap.masconAr) { double CentreGal = MasCon.centreGal; double CentreLat = MasCon.centreLat; double CentreLong = MasCon.centreLong; double DegDiam = MasCon.diamdeg; double DegRad = DegDiam / 2.0; double UpperBoundLat = CentreLat + DegRad; double LowerBoundLat = CentreLat - DegRad; double UpperBoundLong = CentreLong + DegRad; double LowerBoundLong = CentreLong - DegRad; if (UpperBoundLat > 90) { UpperBoundLat = Math.Abs(UpperBoundLat - 180); } if (LowerBoundLat < 90) { LowerBoundLat = -1 * (UpperBoundLat + 180); } if (UpperBoundLong > 180) { UpperBoundLong = UpperBoundLong - 360; } if (UpperBoundLong < -180) { UpperBoundLong = UpperBoundLong + 360; } if (IsBetween(VesselLat, UpperBoundLat, LowerBoundLat)) { LatitudeWithin = true; } if (IsBetween(VesselLong, UpperBoundLong, LowerBoundLong)) { LongitudeWithin = true; } if (LatitudeWithin && LongitudeWithin) { break; } } if (LatitudeWithin && LongitudeWithin) { WithinEffectRange = true; } } } return(WithinEffectRange); }
internal static Mascon LocalMasCon(Vessel vessel) { GravityMap LocalGravityMap = ThisGravityMap(vessel.orbitDriver.orbit.referenceBody.GetName()); Mascon Local = new Mascon(); if (LocalGravityMap.masconAr.Count() > 0) { double VesselLat = vessel.latitude; double VesselLong = vessel.longitude; bool LatitudeWithin = false; bool LongitudeWithin = false; foreach (Mascon MasCon in LocalGravityMap.masconAr) { int idx = MasCon.id; double CentreGal = MasCon.centreGal; double CentreLat = MasCon.centreLat; double CentreLong = MasCon.centreLong; double DegDiam = MasCon.diamdeg; double DegRad = DegDiam / 2.0; double UpperBoundLat = CentreLat + DegRad; double LowerBoundLat = CentreLat - DegRad; double UpperBoundLong = CentreLong + DegRad; double LowerBoundLong = CentreLong - DegRad; if (UpperBoundLat > 90) { UpperBoundLat = Math.Abs(UpperBoundLat - 180); } if (LowerBoundLat < 90) { LowerBoundLat = -1 * (UpperBoundLat + 180); } if (UpperBoundLong > 180) { UpperBoundLong = UpperBoundLong - 360; } if (LowerBoundLong < -180) { LowerBoundLong = LowerBoundLong + 360; } if (IsBetween(VesselLat, UpperBoundLat, LowerBoundLat)) { LatitudeWithin = true; } if (IsBetween(VesselLong, UpperBoundLong, LowerBoundLong)) { LongitudeWithin = true; } if (LatitudeWithin && LongitudeWithin) { Local = MasCon; break; } } } return(Local); }