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 longitude extremum.
28 * <p>This detector identifies when a spacecraft reaches its
29 * extremum longitudes with respect to a central body.</p>
30 * @author Luc Maisonobe
31 * @since 7.1
32 */
33 public class LongitudeExtremumDetector extends AbstractDetector<LongitudeExtremumDetector> {
34
35 /** Body on which the longitude 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 longitude is defined
43 */
44 public LongitudeExtremumDetector(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 longitude is defined
52 */
53 public LongitudeExtremumDetector(final double maxCheck, final double threshold,
54 final OneAxisEllipsoid body) {
55 this(new EventDetectionSettings(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 detectionSettings event detection settings
66 * @param handler event handler to call at event occurrences
67 * @param body body on which the longitude is defined
68 * @since 13.0
69 */
70 protected LongitudeExtremumDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
71 final OneAxisEllipsoid body) {
72 super(detectionSettings, handler);
73 this.body = body;
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 protected LongitudeExtremumDetector create(final EventDetectionSettings detectionSettings,
79 final EventHandler newHandler) {
80 return new LongitudeExtremumDetector(detectionSettings, newHandler, body);
81 }
82
83 /** Get the body on which the geographic zone is defined.
84 * @return body on which the geographic zone is defined
85 */
86 public BodyShape getBody() {
87 return body;
88 }
89
90 /** Compute the value of the detection function.
91 * <p>
92 * The value is the spacecraft longitude time derivative.
93 * </p>
94 * @param s the current state information: date, kinematics, attitude
95 * @return spacecraft longitude time derivative
96 */
97 public double g(final SpacecraftState s) {
98
99 // convert state to geodetic coordinates
100 final FieldGeodeticPoint<UnivariateDerivative2> gp =
101 body.transform(s.getPVCoordinates(), s.getFrame(), s.getDate());
102
103 // longitude time derivative
104 return gp.getLongitude().getFirstDerivative();
105
106 }
107
108 }