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 AbstractDetector<ElevationExtremumDetector> {

  43.     /** Topocentric frame in which elevation should be evaluated. */
  44.     private final TopocentricFrame topo;

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

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

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

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     protected ElevationExtremumDetector create(final EventDetectionSettings detectionSettings,
  82.                                               final EventHandler newHandler) {
  83.         return new ElevationExtremumDetector(detectionSettings, newHandler, topo);
  84.     }

  85.     /**
  86.      * Returns the topocentric frame centered on ground point.
  87.      * @return topocentric frame centered on ground point
  88.      */
  89.     public TopocentricFrame getTopocentricFrame() {
  90.         return this.topo;
  91.     }

  92.     /** Get the elevation value.
  93.      * @param s the current state information: date, kinematics, attitude
  94.      * @return spacecraft elevation
  95.      */
  96.     public double getElevation(final SpacecraftState s) {
  97.         return topo.getElevation(s.getPosition(), s.getFrame(), s.getDate());
  98.     }

  99.     /** Compute the value of the detection function.
  100.      * <p>
  101.      * The value is the spacecraft elevation first time derivative.
  102.      * </p>
  103.      * @param s the current state information: date, kinematics, attitude
  104.      * @return spacecraft elevation first time derivative
  105.      */
  106.     public double g(final SpacecraftState s) {

  107.         // get position, velocity of spacecraft in topocentric frame
  108.         final KinematicTransform inertToTopo = s.getFrame().getKinematicTransformTo(topo, s.getDate());
  109.         final TimeStampedPVCoordinates pvTopo = inertToTopo.transformOnlyPV(s.getPVCoordinates());

  110.         // convert the coordinates to UnivariateDerivative1 based vector
  111.         // instead of having vector position, then vector velocity then vector acceleration
  112.         // we get one vector and each coordinate is a DerivativeStructure containing
  113.         // value, first time derivative (we don't need second time derivative here)
  114.         final FieldVector3D<UnivariateDerivative1> pvDS = pvTopo.toUnivariateDerivative1Vector();

  115.         // compute elevation and its first time derivative
  116.         final UnivariateDerivative1 elevation = pvDS.getZ().divide(pvDS.getNorm()).asin();

  117.         // return elevation first time derivative
  118.         return elevation.getDerivative(1);

  119.     }

  120. }