ElevationDetectionAdaptableIntervalFactory.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.propagation.events.intervals;

  18. import org.hipparchus.util.FastMath;
  19. import org.orekit.frames.TopocentricFrame;
  20. import org.orekit.frames.Transform;
  21. import org.orekit.orbits.Orbit;

  22. /**
  23.  * Factory class for {@link AdaptableInterval} suitable for elevation detection on eccentric orbits.
  24.  * It requires {@link org.orekit.propagation.SpacecraftState} to be based on {@link Orbit} in order to work.
  25.  * @see AdaptableInterval
  26.  * @see org.orekit.propagation.events.ApsideDetector
  27.  * @see org.orekit.propagation.events.EventSlopeFilter
  28.  * @author Luc Maisonobe
  29.  * @since 12.1
  30.  */
  31. public class ElevationDetectionAdaptableIntervalFactory {

  32.     /** Default elevation above which interval should be switched to fine interval (-5°).
  33.      * @since 13.0
  34.      */
  35.     public static final double DEFAULT_ELEVATION_SWITCH_INF = FastMath.toRadians(-5.0);

  36.     /** Default elevation below which interval should be switched to fine interval (+15°).
  37.      * @since 13.0
  38.      */
  39.     public static final double DEFAULT_ELEVATION_SWITCH_SUP = FastMath.toRadians(15.0);

  40.     /**
  41.      * Private constructor.
  42.      */
  43.     private ElevationDetectionAdaptableIntervalFactory() {
  44.         // factory class
  45.     }

  46.     /**
  47.      * Method providing a candidate {@link AdaptableInterval} for arbitrary elevation detection with forward propagation.
  48.      * It uses a Keplerian, eccentric approximation.
  49.      * @param topo topocentric frame centered at ground interest point
  50.      * @param elevationSwitchInf elevation above which interval will switch to {@code fineCheckInterval}
  51.      *                        (typically {@link #DEFAULT_ELEVATION_SWITCH_INF} which is -5°)
  52.      * @param elevationSwitchSup elevation below which interval will switch to {@code fineCheckInterval}
  53.      *                        (typically {@link #DEFAULT_ELEVATION_SWITCH_SUP} which is +15°)
  54.      * @param fineCheckInterval check interval to use when elevation is
  55.      *                          between {@code elevationSwitchInf} and {@code elevationSwitchSup}
  56.      * @return adaptable interval for detection of elevation with respect to {@code topo}
  57.      * @since 13.0
  58.      */
  59.     public static AdaptableInterval getAdaptableInterval(final TopocentricFrame topo,
  60.                                                          final double elevationSwitchInf,
  61.                                                          final double elevationSwitchSup,
  62.                                                          final double fineCheckInterval) {
  63.         return (state, isForward) -> {
  64.             final double elevation = topo.getElevation(state.getPosition(), state.getFrame(), state.getDate());
  65.             if (elevation <= elevationSwitchInf || elevation >= elevationSwitchSup) {
  66.                 // we are far from visibility switch, estimate some large interval with huge margins

  67.                 // rotation rate of the topocentric frame
  68.                 final Transform topoToInertial = topo.getTransformTo(state.getFrame(), state.getDate());
  69.                 final double topoAngularVelocity = topoToInertial.getAngular().getRotationRate().getNorm();

  70.                 // max angular rate of spacecraft (i.e. rate at perigee)
  71.                 final Orbit orbit = state.getOrbit();
  72.                 final double e     = orbit.getE();
  73.                 final double rp    = orbit.getA() * (1 - e);
  74.                 final double vp    = FastMath.sqrt(orbit.getMu() * (1 + e) / rp);
  75.                 final double rateP = vp / rp;

  76.                 // upper boundary of elevation rate
  77.                 final double maxElevationRate = topoAngularVelocity + rateP;

  78.                 // angular distance to the closest switch
  79.                 final double deltaElevationSwitch = elevation <= elevationSwitchInf ?
  80.                                                     elevationSwitchInf - elevation :
  81.                                                     elevation - elevationSwitchSup;

  82.                 return FastMath.max(fineCheckInterval, deltaElevationSwitch / maxElevationRate);

  83.             } else {
  84.                 // we are close to visibility change, switch to fine check interval
  85.                 return fineCheckInterval;
  86.             }
  87.         };
  88.     }

  89. }