diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp index a87318ddf..a0f895d70 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp @@ -1221,6 +1221,12 @@ Array Orbit::ComputePassesWithModel( while (true) { + if ((isForwardPropagated && (previousInstant >= anEndInstant)) || + (!isForwardPropagated && (previousInstant <= anEndInstant))) + { + break; + } + std::tie(northPointCrossing, descendingNodeCrossing, southPointCrossing, passBreakCrossing) = Orbit::ComputeCrossings(aModel, previousInstant, stepDuration, isForwardPropagated, anEndInstant); @@ -1235,6 +1241,15 @@ Array Orbit::ComputePassesWithModel( passes.add(pass); + // if forward propagating and the pass has an undefined PassBreak, then we have crossed the end of the interval + // if backward propagating and the pass has an undefined AscendingNode, then we have crossed the end of the + // interval + if ((isForwardPropagated && !pass.accessInstantAtPassBreak().isDefined()) || + (!isForwardPropagated && !pass.accessInstantAtAscendingNode().isDefined())) + { + break; + } + revolutionNumber += isForwardPropagated ? 1 : -1; previousPassEndInstant = passBreakCrossing; @@ -1249,15 +1264,6 @@ Array Orbit::ComputePassesWithModel( stepDuration = *std::min_element(durations.begin(), durations.end()) / 2.0; } - // if forward propagating and the pass has an undefined PassBreak, then we have crossed the end of the interval - // if backward propagating and the pass has an undefined AscendingNode, then we have crossed the end of the - // interval - if ((isForwardPropagated && !pass.accessInstantAtPassBreak().isDefined()) || - (!isForwardPropagated && !pass.accessInstantAtAscendingNode().isDefined())) - { - break; - } - previousInstant = isForwardPropagated ? pass.accessInstantAtPassBreak() + Duration::Microseconds(1.0) : pass.accessInstantAtAscendingNode() - Duration::Microseconds(1.0); } @@ -1296,6 +1302,11 @@ Tuple Orbit::ComputeCrossings( Instant descendingNodeCrossing = Instant::Undefined(); Instant passBreakCrossing = Instant::Undefined(); + if (anEndInstant.isDefined() && (previousInstant >= anEndInstant)) + { + return {northPointCrossing, descendingNodeCrossing, southPointCrossing, passBreakCrossing}; + } + const Instant epoch = aModel.getEpoch(); const State previousState = aModel.calculateStateAt(previousInstant);