private void SetTransferDetails() { DepartureSelected = DepartureMin + (vectSelected.x - PlotPosition.x) * xResolution; TravelSelected = TravelMax - (vectSelected.y - PlotPosition.y) * yResolution; LambertSolver.TransferDeltaV(cbOrigin, cbDestination, DepartureSelected, TravelSelected, InitialOrbitAltitude, FinalOrbitAltitude, out TransferSelected); TransferSelected.CalcEjectionValues(); mbTWP.EjectAngle.AngleTargetValue = TransferSelected.EjectionAngle * LambertSolver.Rad2Deg; mbTWP.EjectAngle.DrawToRetrograde = TransferSelected.EjectionAngleIsRetrograde; mbTWP.PhaseAngle.AngleTargetValue = TransferSelected.PhaseAngle * LambertSolver.Rad2Deg; if (!mbTWP.PhaseAngle.ShowTargetAngle) { mbTWP.PhaseAngle.ShowTargetAngle = true; } }
private void SetTransferDetails() { DepartureSelected = DepartureMin + (vectSelected.x - PlotPosition.x) * xResolution; TravelSelected = TravelMax - (vectSelected.y - PlotPosition.y) * yResolution; LambertSolver.TransferDeltaV(cbOrigin, cbDestination, DepartureSelected, TravelSelected, InitialOrbitAltitude, FinalOrbitAltitude, out TransferSelected); if (TransferSelected != null) { //Only if its not a NaN TransferSelected.CalcEjectionValues(); if (TransferWindowPlanner.lstScenesForAngles.Contains(HighLogic.LoadedScene)) { mbTWP.EjectAngle.AngleTargetValue = TransferSelected.EjectionAngle * LambertSolver.Rad2Deg; mbTWP.EjectAngle.DrawToRetrograde = TransferSelected.EjectionAngleIsRetrograde; mbTWP.PhaseAngle.AngleTargetValue = TransferSelected.PhaseAngle * LambertSolver.Rad2Deg; if (!mbTWP.PhaseAngle.ShowTargetAngle) { mbTWP.PhaseAngle.ShowTargetAngle = true; } } } }
void bw_GeneratePorkchop(object sender, DoWorkEventArgs e) { try { sumlogDeltaV = 0; sumSqLogDeltaV = 0; maxDeltaV = 0; minDeltaV = Double.MaxValue; //Loop through getting the DeltaV's and assigning em all to an array Int32 iCurrent = 0; #if DEBUG ////////need to make sure this bombing out cause file is locked doesnt stop process :) String strCSVLine = ""; try { if (System.IO.File.Exists(String.Format("{0}/DeltaVWorking-{1}-{2}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName))) { System.IO.File.Delete(String.Format("{0}/DeltaVWorking-{1}-{2}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName)); } } catch (Exception ex) { LogFormatted("Unable to delete file:{0}", ex.Message); } #endif LogFormatted("Generating DeltaV Values"); for (int x = 0; x < PlotWidth; x++) { #if DEBUG strCSVLine = ""; #endif //LogFormatted("{0:0.000}-{1}", workingpercent, iCurrent); for (int y = 0; y < PlotHeight; y++) { //have to keep this this way so the texture draws the right way around iCurrent = (int)(y * PlotWidth + x); //Set the Value for this position to be the DeltaV of this Transfer DeltaVs[iCurrent] = LambertSolver.TransferDeltaV(cbOrigin, cbDestination, DepartureMin + ((Double)x * xResolution), TravelMax - ((Double)y * yResolution), InitialOrbitAltitude, FinalOrbitAltitude); //LogFormatted("dt: {0} TT:{1}", TravelMax - ((Double)y * yResolution), transferTemp.TravelTime); #if DEBUG strCSVLine += String.Format("{0:0.00},", DeltaVs[iCurrent]); #endif /////////////// Long Running //////////////////////////// //LogFormatted("{0}x{1} ({3}) = {2:0}", x, y, DeltaVs[iCurrent],iCurrent); if (DeltaVs[iCurrent] > maxDeltaV) { maxDeltaV = DeltaVs[iCurrent]; } if (DeltaVs[iCurrent] < minDeltaV) { minDeltaV = DeltaVs[iCurrent]; minDeltaVPoint = new Vector2(x, y); } logDeltaV = Math.Log(DeltaVs[iCurrent]); sumlogDeltaV += logDeltaV; sumSqLogDeltaV += logDeltaV * logDeltaV; workingpercent = (x * PlotHeight + y) / (Double)(PlotHeight * PlotWidth); } #if DEBUG try { System.IO.File.AppendAllText(String.Format("{0}/DeltaVWorking.csv", Resources.PathPlugin), strCSVLine.TrimEnd(',') + "\r\n"); } catch (Exception) { } #endif } Double mean, stddev; //Calculate the ColorIndex for the plot - BUT DONT AFFECT TEXTURES ON THE BW THREAD LogFormatted("Working out Log Values to determine DeltaV->Color Mapping"); logMinDeltaV = Math.Log(DeltaVs.Min()); mean = sumlogDeltaV / DeltaVs.Length; stddev = Math.Sqrt(sumSqLogDeltaV / DeltaVs.Length - mean * mean); logMaxDeltaV = Math.Min(Math.Log(maxDeltaV), mean + 2 * stddev); if (DeltaVColorPalette == null) { GenerateDeltaVPalette(); } LogFormatted("Placing ColorIndexes in array"); for (int y = 0; y < PlotHeight; y++) { for (int x = 0; x < PlotWidth; x++) { iCurrent = (Int32)(y * PlotWidth + x); logDeltaV = Math.Log(DeltaVs[iCurrent]); double relativeDeltaV = (logDeltaV - logMinDeltaV) / (logMaxDeltaV - logMinDeltaV); Int32 ColorIndex = Math.Min((Int32)(Math.Floor(relativeDeltaV * DeltaVColorPalette.Count)), DeltaVColorPalette.Count - 1); DeltaVsColorIndex[iCurrent] = ColorIndex; } } //Set the Best Transfer vectSelected = new Vector2(PlotPosition.x + minDeltaVPoint.x, PlotPosition.y + minDeltaVPoint.y); SetTransferDetails(); } catch (Exception ex) { LogFormatted("ERROR: Background Worker Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace); } }
void bw_GenerateDataPorkchop(object sender, DoWorkEventArgs e) { try { //Loop through getting the DeltaV's and assigning em all to an array Int32 iCurrent = 0; ////////need to make sure this bombing out cause file is locked doesnt stop process :) //String strCSVLine = "", strCSVLine2 = ""; Boolean blnCSVTransferFirst = true; try { if (System.IO.File.Exists(String.Format("{0}/DeltaVWorking-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear))) { System.IO.File.Delete(String.Format("{0}/DeltaVWorking-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear)); } } catch (Exception ex) { LogFormatted("Unable to delete file:{0}", ex.Message); } try { if (System.IO.File.Exists(String.Format("{0}/DeltaVTravelWorking-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear))) { System.IO.File.Delete(String.Format("{0}/DeltaVTravelWorking-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear)); } } catch (Exception ex) { LogFormatted("Unable to delete file:{0}", ex.Message); } try { if (System.IO.File.Exists(String.Format("{0}/DeltaVDaily-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear))) { System.IO.File.Delete(String.Format("{0}/DeltaVDaily-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear)); } } catch (Exception ex) { LogFormatted("Unable to delete file:{0}", ex.Message); } LogFormatted("Generating DeltaV Values"); for (int x = 0; x < PlotWidth; x++) { //strCSVLine = ""; TransferDetails transferDailyBest = new TransferDetails(); Double transferDailyBestDV = Double.MaxValue; //LogFormatted("{0:0.000}-{1}", workingpercent, iCurrent); for (int y = 0; y < PlotHeight; y++) { //have to keep this this way so the texture draws the right way around iCurrent = (int)(y * PlotWidth + x); TransferDetails transferTemp; //Set the Value for this position to be the DeltaV of this Transfer DeltaVs[iCurrent] = LambertSolver.TransferDeltaV(cbOrigin, cbDestination, DepartureMin + ((Double)x * xResolution), TravelMax - ((Double)y * yResolution), InitialOrbitAltitude, FinalOrbitAltitude, out transferTemp); //LogFormatted("dt: {0} TT:{1}", TravelMax - ((Double)y * yResolution), transferTemp.TravelTime); //strCSVLine += String.Format("{0:0.00},", DeltaVs[iCurrent]); //if (blnCSVTransferFirst) // strCSVLine2 += String.Format("{0:0.00},", transferTemp.TravelTime); if (transferTemp.DVTotal < transferDailyBestDV) { transferDailyBest = transferTemp; transferDailyBestDV = transferTemp.DVTotal; } /////////////// Long Running //////////////////////////// //LogFormatted("{0}x{1} ({3}) = {2:0}", x, y, DeltaVs[iCurrent],iCurrent); if (DeltaVs[iCurrent] > maxDeltaV) { maxDeltaV = DeltaVs[iCurrent]; } if (DeltaVs[iCurrent] < minDeltaV) { minDeltaV = DeltaVs[iCurrent]; minDeltaVPoint = new Vector2(x, y); } logDeltaV = Math.Log(DeltaVs[iCurrent]); sumlogDeltaV += logDeltaV; sumSqLogDeltaV += logDeltaV * logDeltaV; workingpercent = (x * PlotHeight + y) / (Double)(PlotHeight * PlotWidth); } try { //System.IO.File.AppendAllText(String.Format("{0}/DeltaVWorking-{1}-{2}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName), strCSVLine.TrimEnd(',') + "\r\n"); } catch (Exception) { } try { if (blnCSVTransferFirst) { //System.IO.File.AppendAllText(String.Format("{0}/DeltaVTravelWorking-{1}-{2}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName), strCSVLine2.TrimEnd(',') + "\r\n"); blnCSVTransferFirst = false; } } catch (Exception) { } try { System.IO.File.AppendAllText(String.Format("{0}/DeltaVDaily-{1}-{2}-{3}.csv", Resources.PathPlugin, cbOrigin.bodyName, cbDestination.bodyName, lstPlots[CurrentPlot].DepMinYear), //String.Format("{0:0.00},{1:0.00},{2:0.00}\r\n", transferDailyBest.DepartureTime, transferDailyBest.DVTotal, transferDailyBest.TravelTime)); String.Format("{0:0.00},{1:0.00},{2:0.00},\"{3}\",\"{4}\"\r\n", transferDailyBest.DepartureTime, transferDailyBest.DVTotal, transferDailyBest.TravelTime, new KSPDateTime(transferDailyBest.DepartureTime).ToStringStandard(DateStringFormatsEnum.KSPFormat), new KSPTimeSpan(transferDailyBest.TravelTime).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLong))); } catch (Exception) { } } } catch (Exception ex) { LogFormatted("ERROR: Background Worker Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace); } }