From 05847251b20bdf9f20cc4ac6f96d62b9a014d073 Mon Sep 17 00:00:00 2001 From: Andy Borrell Date: Wed, 28 Aug 2019 18:43:22 +0100 Subject: [PATCH] Larger y-axis transfer time range for more eccentric orbits --- javascripts/missionform.js | 18 +++++++++++++----- src/missionform.coffee | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) mode change 100644 => 100755 javascripts/missionform.js diff --git a/javascripts/missionform.js b/javascripts/missionform.js old mode 100644 new mode 100755 index dca300d..6c3b853 --- a/javascripts/missionform.js +++ b/javascripts/missionform.js @@ -368,12 +368,20 @@ }; updateAdvancedControls = function() { - var departureRange, destination, hohmannTransfer, hohmannTransferTime, maxDays, maxDeparture, minDays, minDeparture, origin, referenceBody, synodicPeriod; + var departureRange, destination, destinationApoapsis, destinationPeriapsis, maxDays, maxDeparture, maxHohmannTransferTime, minDays, minDeparture, minHohmannTransferTime, origin, originApopsis, originPeriapsis, referenceBody, synodicPeriod; origin = this.origin(); destination = this.destination(); referenceBody = origin.orbit.referenceBody; - hohmannTransfer = Orbit.fromApoapsisAndPeriapsis(referenceBody, destination.orbit.semiMajorAxis, origin.orbit.semiMajorAxis, 0, 0, 0, 0); - hohmannTransferTime = hohmannTransfer.period() / 2; + originPeriapsis = origin.orbit.periapsis(); + originApopsis = origin.orbit.apoapsis(); + destinationPeriapsis = destination.orbit.periapsis(); + destinationApoapsis = destination.orbit.apoapsis(); + if (destinationPeriapsis <= originApopsis && originPeriapsis <= destinationApoapsis) { + minHohmannTransferTime = 0; + } else { + minHohmannTransferTime = Orbit.fromApoapsisAndPeriapsis(referenceBody, destinationPeriapsis, originPeriapsis, 0, 0, 0, 0).period() / 2; + } + maxHohmannTransferTime = Orbit.fromApoapsisAndPeriapsis(referenceBody, destinationApoapsis, originApopsis, 0, 0, 0, 0).period() / 2; synodicPeriod = Math.abs(1 / (1 / destination.orbit.period() - 1 / origin.orbit.period())); departureRange = Math.min(2 * synodicPeriod, 2 * origin.orbit.period()) / KerbalTime.secondsPerDay(); if (departureRange < 0.1) { @@ -385,8 +393,8 @@ } minDeparture = KerbalTime.fromDate($('#earliestDepartureYear').val(), $('#earliestDepartureDay').val()).t / KerbalTime.secondsPerDay(); maxDeparture = minDeparture + departureRange; - minDays = Math.max(hohmannTransferTime - destination.orbit.period(), hohmannTransferTime / 2) / KerbalTime.secondsPerDay(); - maxDays = minDays + Math.min(2 * destination.orbit.period(), hohmannTransferTime) / KerbalTime.secondsPerDay(); + minDays = Math.max(minHohmannTransferTime - destination.orbit.period(), minHohmannTransferTime / 2) / KerbalTime.secondsPerDay(); + maxDays = Math.max(maxHohmannTransferTime - destination.orbit.period(), maxHohmannTransferTime / 2) / KerbalTime.secondsPerDay() + Math.min(2 * destination.orbit.period(), maxHohmannTransferTime) / KerbalTime.secondsPerDay(); minDays = minDays < 10 ? minDays.toFixed(2) : minDays.toFixed(); maxDays = maxDays < 10 ? maxDays.toFixed(2) : maxDays.toFixed(); $('#latestDepartureYear').val((maxDeparture / KerbalTime.daysPerYear | 0) + 1); diff --git a/src/missionform.coffee b/src/missionform.coffee index afe4493..8c40385 100644 --- a/src/missionform.coffee +++ b/src/missionform.coffee @@ -252,8 +252,17 @@ class MissionForm origin = @origin() destination = @destination() referenceBody = origin.orbit.referenceBody - hohmannTransfer = Orbit.fromApoapsisAndPeriapsis(referenceBody, destination.orbit.semiMajorAxis, origin.orbit.semiMajorAxis, 0, 0, 0, 0) - hohmannTransferTime = hohmannTransfer.period() / 2 + originPeriapsis = origin.orbit.periapsis() + originApopsis = origin.orbit.apoapsis() + destinationPeriapsis = destination.orbit.periapsis() + destinationApoapsis = destination.orbit.apoapsis() + if destinationPeriapsis <= originApopsis && originPeriapsis <= destinationApoapsis + # The orbits potentially overlap, so no lower limit on transfer time + minHohmannTransferTime = 0; + else + minHohmannTransferTime = Orbit.fromApoapsisAndPeriapsis(referenceBody, destinationPeriapsis, originPeriapsis, 0, 0, 0, 0).period() / 2; + maxHohmannTransferTime = Orbit.fromApoapsisAndPeriapsis(referenceBody, destinationApoapsis, originApopsis, 0, 0, 0, 0).period() / 2; + synodicPeriod = Math.abs(1 / (1 / destination.orbit.period() - 1 / origin.orbit.period())) departureRange = Math.min(2 * synodicPeriod, 2 * origin.orbit.period()) / KerbalTime.secondsPerDay() @@ -266,8 +275,9 @@ class MissionForm minDeparture = KerbalTime.fromDate($('#earliestDepartureYear').val(), $('#earliestDepartureDay').val()).t / KerbalTime.secondsPerDay() maxDeparture = minDeparture + departureRange - minDays = Math.max(hohmannTransferTime - destination.orbit.period(), hohmannTransferTime / 2) / KerbalTime.secondsPerDay() - maxDays = minDays + Math.min(2 * destination.orbit.period(), hohmannTransferTime) / KerbalTime.secondsPerDay() + minDays = Math.max(minHohmannTransferTime - destination.orbit.period(), minHohmannTransferTime / 2) / KerbalTime.secondsPerDay() + maxDays = Math.max(maxHohmannTransferTime - destination.orbit.period(), maxHohmannTransferTime / 2) / KerbalTime.secondsPerDay() + + Math.min(2 * destination.orbit.period(), maxHohmannTransferTime) / KerbalTime.secondsPerDay(); minDays = if minDays < 10 then minDays.toFixed(2) else minDays.toFixed() maxDays = if maxDays < 10 then maxDays.toFixed(2) else maxDays.toFixed()