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