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  
19  import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
20  import org.orekit.bodies.BodyShape;
21  import org.orekit.bodies.FieldGeodeticPoint;
22  import org.orekit.bodies.OneAxisEllipsoid;
23  import org.orekit.propagation.SpacecraftState;
24  import org.orekit.propagation.events.handlers.EventHandler;
25  import org.orekit.propagation.events.handlers.StopOnIncreasing;
26  
27  /** Detector for geographic latitude extremum.
28   * <p>This detector identifies when a spacecraft reaches its
29   * extremum latitudes with respect to a central body.</p>
30   * @author Luc Maisonobe
31   * @since 7.1
32   */
33  public class LatitudeExtremumDetector extends AbstractDetector<LatitudeExtremumDetector> {
34  
35      /** Body on which the latitude is defined. */
36      private OneAxisEllipsoid body;
37  
38      /** Build a new detector.
39       * <p>The new instance uses default values for maximal checking interval
40       * ({@link #DEFAULT_MAX_CHECK}) and convergence threshold ({@link
41       * #DEFAULT_THRESHOLD}).</p>
42       * @param body body on which the latitude is defined
43       */
44      public LatitudeExtremumDetector(final OneAxisEllipsoid body) {
45          this(DEFAULT_MAX_CHECK, DEFAULT_THRESHOLD, body);
46      }
47  
48      /** Build a detector.
49       * @param maxCheck maximal checking interval (s)
50       * @param threshold convergence threshold (s)
51       * @param body body on which the latitude is defined
52       */
53      public LatitudeExtremumDetector(final double maxCheck, final double threshold,
54                                      final OneAxisEllipsoid body) {
55          this(new EventDetectionSettings(maxCheck, threshold, DEFAULT_MAX_ITER), new StopOnIncreasing(), body);
56      }
57  
58      /** Protected constructor with full parameters.
59       * <p>
60       * This constructor is not public as users are expected to use the builder
61       * API with the various {@code withXxx()} methods to set up the instance
62       * in a readable manner without using a huge amount of parameters.
63       * </p>
64       * @param detectionSettings event detection settings
65       * @param handler event handler to call at event occurrences
66       * @param body body on which the latitude is defined
67       */
68      protected LatitudeExtremumDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
69                                         final OneAxisEllipsoid body) {
70          super(detectionSettings, handler);
71          this.body = body;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      protected LatitudeExtremumDetector create(final EventDetectionSettings detectionSettings,
77                                                final EventHandler newHandler) {
78          return new LatitudeExtremumDetector(detectionSettings, newHandler, body);
79      }
80  
81      /** Get the body on which the geographic zone is defined.
82       * @return body on which the geographic zone is defined
83       */
84      public BodyShape getBody() {
85          return body;
86      }
87  
88      /** Compute the value of the detection function.
89       * <p>
90       * The value is the spacecraft latitude time derivative.
91       * </p>
92       * @param s the current state information: date, kinematics, attitude
93       * @return spacecraft latitude time derivative
94       */
95      public double g(final SpacecraftState s) {
96  
97          // convert state to geodetic coordinates
98          final FieldGeodeticPoint<UnivariateDerivative2> gp =
99                          body.transform(s.getPVCoordinates(), s.getFrame(), s.getDate());
100 
101         // latitude time derivative
102         return gp.getLatitude().getFirstDerivative();
103 
104     }
105 
106 }