ElevationExtremumDetector.java

  1. /* Copyright 2002-2025 CS GROUP
  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;

  18. import org.hipparchus.analysis.differentiation.UnivariateDerivative1;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.orekit.frames.KinematicTransform;
  21. import org.orekit.frames.TopocentricFrame;
  22. import org.orekit.propagation.SpacecraftState;
  23. import org.orekit.propagation.events.handlers.EventHandler;
  24. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  25. import org.orekit.utils.TimeStampedPVCoordinates;

  26. /** Detector for elevation extremum with respect to a ground point.
  27.  * <p>This detector identifies when a spacecraft reaches its
  28.  * extremum elevation with respect to a ground point.</p>
  29.  * <p>
  30.  * As in most cases only the elevation maximum is needed and the
  31.  * minimum is often irrelevant, this detector is often wrapped into
  32.  * an {@link EventSlopeFilter event slope filter} configured with
  33.  * {@link FilterType#TRIGGER_ONLY_DECREASING_EVENTS} (i.e. when the
  34.  * elevation derivative decreases from positive values to negative values,
  35.  * which correspond to a maximum). Setting up this filter saves some computation
  36.  * time as the elevation minimum occurrences are not even looked at. It is
  37.  * however still often necessary to do an additional filtering
  38.  * </p>
  39.  * @author Luc Maisonobe
  40.  * @since 7.1
  41.  */
  42. public class ElevationExtremumDetector extends AbstractTopocentricDetector<ElevationExtremumDetector> {

  43.     /** Build a new detector.
  44.      * <p>The new instance uses default values for maximal checking interval
  45.      * ({@link #DEFAULT_MAX_CHECK}) and convergence threshold ({@link
  46.      * #DEFAULT_THRESHOLD}).</p>
  47.      * @param topo topocentric frame centered on ground point
  48.      */
  49.     public ElevationExtremumDetector(final TopocentricFrame topo) {
  50.         this(DEFAULT_MAX_CHECK, DEFAULT_THRESHOLD, topo);
  51.     }

  52.     /** Build a detector.
  53.      * @param maxCheck maximal checking interval (s)
  54.      * @param threshold convergence threshold (s)
  55.      * @param topo topocentric frame centered on ground point
  56.      */
  57.     public ElevationExtremumDetector(final double maxCheck, final double threshold,
  58.                                      final TopocentricFrame topo) {
  59.         this(new EventDetectionSettings(maxCheck, threshold, DEFAULT_MAX_ITER), new StopOnIncreasing(), topo);
  60.     }

  61.     /** Protected constructor with full parameters.
  62.      * <p>
  63.      * This constructor is not public as users are expected to use the builder
  64.      * API with the various {@code withXxx()} methods to set up the instance
  65.      * in a readable manner without using a huge amount of parameters.
  66.      * </p>
  67.      * @param detectionSettings event detection settings
  68.      * @param handler event handler to call at event occurrences
  69.      * @param topo topocentric frame centered on ground point
  70.      * @since 13.0
  71.      */
  72.     protected ElevationExtremumDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  73.                                         final TopocentricFrame topo) {
  74.         super(detectionSettings, handler, topo);
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     protected ElevationExtremumDetector create(final EventDetectionSettings detectionSettings,
  79.                                               final EventHandler newHandler) {
  80.         return new ElevationExtremumDetector(detectionSettings, newHandler, getTopocentricFrame());
  81.     }

  82.     /** Get the elevation value.
  83.      * @param s the current state information: date, kinematics, attitude
  84.      * @return spacecraft elevation
  85.      */
  86.     public double getElevation(final SpacecraftState s) {
  87.         return getTopocentricFrame().getElevation(s.getPosition(), s.getFrame(), s.getDate());
  88.     }

  89.     /** Compute the value of the detection function.
  90.      * <p>
  91.      * The value is the spacecraft elevation first time derivative.
  92.      * </p>
  93.      * @param s the current state information: date, kinematics, attitude
  94.      * @return spacecraft elevation first time derivative
  95.      */
  96.     public double g(final SpacecraftState s) {

  97.         // get position, velocity of spacecraft in topocentric frame
  98.         final KinematicTransform inertToTopo = s.getFrame().getKinematicTransformTo(getTopocentricFrame(), s.getDate());
  99.         final TimeStampedPVCoordinates pvTopo = inertToTopo.transformOnlyPV(s.getPVCoordinates());

  100.         // convert the coordinates to UnivariateDerivative1 based vector
  101.         // instead of having vector position, then vector velocity then vector acceleration
  102.         // we get one vector and each coordinate is a Taylor expansion containing
  103.         // value, first time derivative (we don't need second time derivative here)
  104.         final FieldVector3D<UnivariateDerivative1> positionUD1 = pvTopo.toUnivariateDerivative1Vector();

  105.         // compute elevation and its first time derivative
  106.         final UnivariateDerivative1 elevation = positionUD1.getDelta();

  107.         // return elevation first time derivative
  108.         return elevation.getFirstDerivative();

  109.     }

  110. }