LongitudeExtremumDetector.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.UnivariateDerivative2;
  19. import org.orekit.bodies.BodyShape;
  20. import org.orekit.bodies.FieldGeodeticPoint;
  21. import org.orekit.bodies.OneAxisEllipsoid;
  22. import org.orekit.propagation.SpacecraftState;
  23. import org.orekit.propagation.events.handlers.EventHandler;
  24. import org.orekit.propagation.events.handlers.StopOnIncreasing;

  25. /** Detector for geographic longitude extremum.
  26.  * <p>This detector identifies when a spacecraft reaches its
  27.  * extremum longitudes with respect to a central body.</p>
  28.  * @author Luc Maisonobe
  29.  * @since 7.1
  30.  */
  31. public class LongitudeExtremumDetector extends AbstractDetector<LongitudeExtremumDetector> {

  32.     /** Body on which the longitude is defined. */
  33.     private OneAxisEllipsoid body;

  34.     /** Build a new detector.
  35.      * <p>The new instance uses default values for maximal checking interval
  36.      * ({@link #DEFAULT_MAX_CHECK}) and convergence threshold ({@link
  37.      * #DEFAULT_THRESHOLD}).</p>
  38.      * @param body body on which the longitude is defined
  39.      */
  40.     public LongitudeExtremumDetector(final OneAxisEllipsoid body) {
  41.         this(DEFAULT_MAX_CHECK, DEFAULT_THRESHOLD, body);
  42.     }

  43.     /** Build a detector.
  44.      * @param maxCheck maximal checking interval (s)
  45.      * @param threshold convergence threshold (s)
  46.      * @param body body on which the longitude is defined
  47.      */
  48.     public LongitudeExtremumDetector(final double maxCheck, final double threshold,
  49.                                     final OneAxisEllipsoid body) {
  50.         this(new EventDetectionSettings(maxCheck, threshold, DEFAULT_MAX_ITER), new StopOnIncreasing(),
  51.              body);
  52.     }

  53.     /** Protected constructor with full parameters.
  54.      * <p>
  55.      * This constructor is not public as users are expected to use the builder
  56.      * API with the various {@code withXxx()} methods to set up the instance
  57.      * in a readable manner without using a huge amount of parameters.
  58.      * </p>
  59.      * @param detectionSettings event detection settings
  60.      * @param handler event handler to call at event occurrences
  61.      * @param body body on which the longitude is defined
  62.      * @since 13.0
  63.      */
  64.     protected LongitudeExtremumDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  65.                                         final OneAxisEllipsoid body) {
  66.         super(detectionSettings, handler);
  67.         this.body = body;
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     protected LongitudeExtremumDetector create(final EventDetectionSettings detectionSettings,
  72.                                                final EventHandler newHandler) {
  73.         return new LongitudeExtremumDetector(detectionSettings, newHandler, body);
  74.     }

  75.     /** Get the body on which the geographic zone is defined.
  76.      * @return body on which the geographic zone is defined
  77.      */
  78.     public BodyShape getBody() {
  79.         return body;
  80.     }

  81.     /** Compute the value of the detection function.
  82.      * <p>
  83.      * The value is the spacecraft longitude time derivative.
  84.      * </p>
  85.      * @param s the current state information: date, kinematics, attitude
  86.      * @return spacecraft longitude time derivative
  87.      */
  88.     public double g(final SpacecraftState s) {

  89.         // convert state to geodetic coordinates
  90.         final FieldGeodeticPoint<UnivariateDerivative2> gp =
  91.                         body.transform(s.getPVCoordinates(), s.getFrame(), s.getDate());

  92.         // longitude time derivative
  93.         return gp.getLongitude().getFirstDerivative();

  94.     }

  95. }