1 /* Copyright 2002-2021 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.Field;
20 import org.hipparchus.CalculusFieldElement;
21 import org.orekit.bodies.FieldGeodeticPoint;
22 import org.orekit.bodies.OneAxisEllipsoid;
23 import org.orekit.propagation.FieldSpacecraftState;
24 import org.orekit.propagation.events.handlers.FieldEventHandler;
25 import org.orekit.propagation.events.handlers.FieldStopOnIncreasing;
26
27 /** Detector for geographic latitude crossing.
28 * <p>This detector identifies when a spacecraft crosses a fixed
29 * latitude with respect to a central body.</p>
30 * @author Luc Maisonobe
31 * @author Evan Ward
32 * @since 9.3
33 */
34 public class FieldLatitudeCrossingDetector <T extends CalculusFieldElement<T>>
35 extends FieldAbstractDetector<FieldLatitudeCrossingDetector<T>, T> {
36
37 /** Body on which the latitude is defined. */
38 private OneAxisEllipsoid body;
39
40 /** Fixed latitude to be crossed. */
41 private final double latitude;
42
43 /** Build a new detector.
44 * <p>The new instance uses default values for maximal checking interval
45 * ({@link #DEFAULT_MAXCHECK}) and convergence threshold ({@link
46 * #DEFAULT_THRESHOLD}).</p>
47 * @param field the type of numbers to use.
48 * @param body body on which the latitude is defined
49 * @param latitude latitude to be crossed
50 */
51 public FieldLatitudeCrossingDetector(final Field<T> field,
52 final OneAxisEllipsoid body,
53 final double latitude) {
54 this(field.getZero().add(DEFAULT_MAXCHECK),
55 field.getZero().add(DEFAULT_THRESHOLD),
56 body,
57 latitude);
58 }
59
60 /** Build a detector.
61 * @param maxCheck maximal checking interval (s)
62 * @param threshold convergence threshold (s)
63 * @param body body on which the latitude is defined
64 * @param latitude latitude to be crossed
65 */
66 public FieldLatitudeCrossingDetector(final T maxCheck,
67 final T threshold,
68 final OneAxisEllipsoid body,
69 final double latitude) {
70 this(maxCheck, threshold, DEFAULT_MAX_ITER, new FieldStopOnIncreasing<>(),
71 body, latitude);
72 }
73
74 /** Private constructor with full parameters.
75 * <p>
76 * This constructor is private as users are expected to use the builder
77 * API with the various {@code withXxx()} methods to set up the instance
78 * in a readable manner without using a huge amount of parameters.
79 * </p>
80 * @param maxCheck maximum checking interval (s)
81 * @param threshold convergence threshold (s)
82 * @param maxIter maximum number of iterations in the event time search
83 * @param handler event handler to call at event occurrences
84 * @param body body on which the latitude is defined
85 * @param latitude latitude to be crossed
86 */
87 private FieldLatitudeCrossingDetector(
88 final T maxCheck,
89 final T threshold,
90 final int maxIter,
91 final FieldEventHandler<? super FieldLatitudeCrossingDetector<T>, T> handler,
92 final OneAxisEllipsoid body,
93 final double latitude) {
94 super(maxCheck, threshold, maxIter, handler);
95 this.body = body;
96 this.latitude = latitude;
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 protected FieldLatitudeCrossingDetector<T> create(
102 final T newMaxCheck,
103 final T newThreshold,
104 final int newMaxIter,
105 final FieldEventHandler<? super FieldLatitudeCrossingDetector<T>, T> newHandler) {
106 return new FieldLatitudeCrossingDetector<>(
107 newMaxCheck, newThreshold, newMaxIter, newHandler, body, latitude);
108 }
109
110 /** Get the body on which the geographic zone is defined.
111 * @return body on which the geographic zone is defined
112 */
113 public OneAxisEllipsoid getBody() {
114 return body;
115 }
116
117 /** Get the fixed latitude to be crossed (radians).
118 * @return fixed latitude to be crossed (radians)
119 */
120 public double getLatitude() {
121 return latitude;
122 }
123
124 /** Compute the value of the detection function.
125 * <p>
126 * The value is the spacecraft latitude minus the fixed latitude to be crossed.
127 * It is positive if the spacecraft is northward and negative if it is southward
128 * with respect to the fixed latitude.
129 * </p>
130 * @param s the current state information: date, kinematics, attitude
131 * @return spacecraft latitude minus the fixed latitude to be crossed
132 */
133 public T g(final FieldSpacecraftState<T> s) {
134
135 // convert state to geodetic coordinates
136 final FieldGeodeticPoint<T> gp = body.transform(
137 s.getPVCoordinates().getPosition(),
138 s.getFrame(),
139 s.getDate());
140
141 // latitude difference
142 return gp.getLatitude().subtract(latitude);
143
144 }
145
146 }