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.ode.events.Action;
21 import org.orekit.orbits.Orbit;
22 import org.orekit.propagation.SpacecraftState;
23 import org.orekit.propagation.events.handlers.EventHandler;
24 import org.orekit.propagation.events.handlers.StopOnIncreasing;
25 import org.orekit.utils.PVCoordinates;
26
27 /** Finder for apside crossing events.
28 * <p>This class finds apside crossing events (i.e. apogee or perigee crossing).</p>
29 * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
30 * propagation at apogee crossing and to {@link Action#STOP stop} propagation
31 * at perigee crossing. This can be changed by calling
32 * {@link #withHandler(EventHandler)} after construction.</p>
33 * <p>Beware that apside detection will fail for almost circular orbits. If
34 * for example an apside detector is used to trigger an {@link
35 * org.orekit.forces.maneuvers.ImpulseManeuver ImpulseManeuver} and the maneuver
36 * change the orbit shape to circular, then the detector may completely fail just
37 * after the maneuver has been performed!</p>
38 * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
39 * @author Luc Maisonobe
40 */
41 public class ApsideDetector extends AbstractDetector<ApsideDetector> {
42
43 /** Build a new instance.
44 * <p>The Keplerian period is used only to set an upper bound for the
45 * max check interval to period/3 and to set the convergence threshold.</p>
46 * @param keplerianPeriod estimate of the Keplerian period
47 * @since 12.1
48 */
49 public ApsideDetector(final double keplerianPeriod) {
50 super(keplerianPeriod / 3, 1e-13 * keplerianPeriod, DEFAULT_MAX_ITER, new StopOnIncreasing());
51 }
52
53 /** Build a new instance.
54 * <p>The orbit is used only to set an upper bound for the
55 * max check interval to period/3 and to set the convergence
56 * threshold according to orbit size</p>
57 * @param orbit initial orbit
58 */
59 public ApsideDetector(final Orbit orbit) {
60 this(orbit.getKeplerianPeriod());
61 }
62
63 /** Build a new instance.
64 * <p>The orbit is used only to set an upper bound for the
65 * max check interval to period/3</p>
66 * @param threshold convergence threshold (s)
67 * @param orbit initial orbit
68 */
69 public ApsideDetector(final double threshold, final Orbit orbit) {
70 super(orbit.getKeplerianPeriod() / 3, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing());
71 }
72
73 /** Public constructor with full parameters.
74 * <p>
75 * This constructor is public because otherwise all accessible ones would require an orbit.
76 * </p>
77 * @param detectionSettings detection settings
78 * @param handler event handler to call at event occurrences
79 * @since 13.0
80 */
81 public ApsideDetector(final EventDetectionSettings detectionSettings, final EventHandler handler) {
82 super(detectionSettings, handler);
83 }
84
85 /** {@inheritDoc} */
86 @Override
87 protected ApsideDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
88 return new ApsideDetector(detectionSettings, newHandler);
89 }
90
91 /** Compute the value of the switching function.
92 * This function computes the dot product of the 2 vectors : position.velocity.
93 * @param s the current state information: date, kinematics, attitude
94 * @return value of the switching function
95 */
96 public double g(final SpacecraftState s) {
97 final PVCoordinates pv = s.getPVCoordinates();
98 return Vector3D.dotProduct(pv.getPosition(), pv.getVelocity());
99 }
100
101 }