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.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.FastMath;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.Utils;
25  import org.orekit.bodies.OneAxisEllipsoid;
26  import org.orekit.frames.FramesFactory;
27  import org.orekit.orbits.EquinoctialOrbit;
28  import org.orekit.orbits.Orbit;
29  import org.orekit.propagation.Propagator;
30  import org.orekit.propagation.SpacecraftState;
31  import org.orekit.propagation.analytical.EcksteinHechlerPropagator;
32  import org.orekit.propagation.events.EventsLogger.LoggedEvent;
33  import org.orekit.propagation.events.handlers.ContinueOnEvent;
34  import org.orekit.time.AbsoluteDate;
35  import org.orekit.time.TimeScale;
36  import org.orekit.time.TimeScalesFactory;
37  import org.orekit.utils.Constants;
38  import org.orekit.utils.IERSConventions;
39  import org.orekit.utils.PVCoordinates;
40  
41  public class LatitudeExtremumDetectorTest {
42  
43      @Test
44      public void testLEO() {
45  
46          final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
47                                                              Constants.WGS84_EARTH_FLATTENING,
48                                                              FramesFactory.getITRF(IERSConventions.IERS_2010, true));
49  
50          LatitudeExtremumDetector d =
51                  new LatitudeExtremumDetector(earth).
52                  withMaxCheck(60).
53                  withThreshold(1.e-6).
54                  withHandler(new ContinueOnEvent());
55  
56          Assertions.assertEquals(60.0, d.getMaxCheckInterval().currentInterval(null, true), 1.0e-15);
57          Assertions.assertEquals(1.0e-6, d.getThreshold(), 1.0e-15);
58          Assertions.assertEquals(AbstractDetector.DEFAULT_MAX_ITER, d.getMaxIterationCount());
59          Assertions.assertSame(earth, d.getBody());
60  
61          final TimeScale utc = TimeScalesFactory.getUTC();
62          final Vector3D position = new Vector3D(-6142438.668, 3492467.56, -25767.257);
63          final Vector3D velocity = new Vector3D(505.848, 942.781, 7435.922);
64          final AbsoluteDate date = new AbsoluteDate(2003, 9, 16, utc);
65          final Orbit orbit = new EquinoctialOrbit(new PVCoordinates(position,  velocity),
66                                                   FramesFactory.getEME2000(), date,
67                                                   Constants.EIGEN5C_EARTH_MU);
68  
69          Propagator propagator =
70              new EcksteinHechlerPropagator(orbit,
71                                            Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS,
72                                            Constants.EIGEN5C_EARTH_MU,
73                                            Constants.EIGEN5C_EARTH_C20,
74                                            Constants.EIGEN5C_EARTH_C30,
75                                            Constants.EIGEN5C_EARTH_C40,
76                                            Constants.EIGEN5C_EARTH_C50,
77                                            Constants.EIGEN5C_EARTH_C60);
78  
79          EventsLogger logger = new EventsLogger();
80          propagator.addEventDetector(logger.monitorDetector(d));
81  
82          propagator.propagate(date.shiftedBy(Constants.JULIAN_DAY));
83          for (LoggedEvent e : logger.getLoggedEvents()) {
84              SpacecraftState state = e.getState();
85              double latitude = earth.transform(state.getPosition(earth.getBodyFrame()),
86                                                earth.getBodyFrame(), null).getLatitude();
87              if (e.isIncreasing()) {
88                  Assertions.assertEquals(-81.863, FastMath.toDegrees(latitude), 0.001);
89              } else {
90                  Assertions.assertEquals(+81.863, FastMath.toDegrees(latitude), 0.001);
91              }
92          }
93          Assertions.assertEquals(29, logger.getLoggedEvents().size());
94  
95      }
96  
97      @BeforeEach
98      public void setUp() {
99          Utils.setDataRoot("regular-data");
100     }
101 
102 }
103