1   /* Copyright 2002-2024 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.DerivativeStructure;
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_MAXCHECK}) 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_MAXCHECK, 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(AdaptableInterval.of(maxCheck), threshold, DEFAULT_MAX_ITER, new StopOnIncreasing(),
56               body);
57      }
58  
59      /** Protected constructor with full parameters.
60       * <p>
61       * This constructor is not public as users are expected to use the builder
62       * API with the various {@code withXxx()} methods to set up the instance
63       * in a readable manner without using a huge amount of parameters.
64       * </p>
65       * @param maxCheck maximum checking interval
66       * @param threshold convergence threshold (s)
67       * @param maxIter maximum number of iterations in the event time search
68       * @param handler event handler to call at event occurrences
69       * @param body body on which the latitude is defined
70       */
71      protected LatitudeExtremumDetector(final AdaptableInterval maxCheck, final double threshold,
72                                         final int maxIter, final EventHandler handler,
73                                         final OneAxisEllipsoid body) {
74          super(maxCheck, threshold, maxIter, handler);
75          this.body = body;
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      protected LatitudeExtremumDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
81                                                final int newMaxIter,
82                                                final EventHandler newHandler) {
83          return new LatitudeExtremumDetector(newMaxCheck, newThreshold, newMaxIter, newHandler, body);
84      }
85  
86      /** Get the body on which the geographic zone is defined.
87       * @return body on which the geographic zone is defined
88       */
89      public BodyShape getBody() {
90          return body;
91      }
92  
93      /** Compute the value of the detection function.
94       * <p>
95       * The value is the spacecraft latitude time derivative.
96       * </p>
97       * @param s the current state information: date, kinematics, attitude
98       * @return spacecraft latitude time derivative
99       */
100     public double g(final SpacecraftState s) {
101 
102         // convert state to geodetic coordinates
103         final FieldGeodeticPoint<DerivativeStructure> gp =
104                         body.transform(s.getPVCoordinates(), s.getFrame(), s.getDate());
105 
106         // latitude time derivative
107         return gp.getLatitude().getPartialDerivative(1);
108 
109     }
110 
111 }