1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation.events.intervals;
18
19 import org.hipparchus.util.FastMath;
20 import org.hipparchus.util.MathUtils;
21 import org.orekit.orbits.KeplerianOrbit;
22 import org.orekit.orbits.Orbit;
23 import org.orekit.orbits.OrbitType;
24
25
26
27
28
29
30
31
32
33
34 public class ApsideDetectionAdaptableIntervalFactory {
35
36
37
38
39 private ApsideDetectionAdaptableIntervalFactory() {
40
41 }
42
43
44
45
46
47
48 public static AdaptableInterval getApsideDetectionAdaptableInterval() {
49 return (state, isForward) -> {
50 final Orbit orbit = state.getOrbit();
51 final KeplerianOrbit keplerianOrbit = convertOrbitIntoKeplerianOne(orbit);
52 final double meanMotion = keplerianOrbit.getKeplerianMeanMotion();
53 final double meanAnomaly = keplerianOrbit.getMeanAnomaly();
54 if (isForward) {
55 final double durationToNextPeriapsis = computeKeplerianDurationToNextPeriapsis(meanAnomaly, meanMotion);
56 final double durationToNextApoapsis = computeKeplerianDurationToNextApoapsis(meanAnomaly, meanMotion);
57 return FastMath.min(durationToNextPeriapsis, durationToNextApoapsis);
58 }
59 else {
60 final double durationFromPreviousPeriapsis = computeKeplerianDurationFromPreviousPeriapsis(meanAnomaly,
61 meanMotion);
62 final double durationFromPreviousApoapsis = computeKeplerianDurationFromPreviousApoapsis(meanAnomaly,
63 meanMotion);
64 return FastMath.min(durationFromPreviousApoapsis, durationFromPreviousPeriapsis);
65 }
66 };
67 }
68
69
70
71
72
73
74 public static AdaptableInterval getPeriapsisDetectionAdaptableInterval() {
75 return (state, isForward) -> {
76 final Orbit orbit = state.getOrbit();
77 final KeplerianOrbit keplerianOrbit = convertOrbitIntoKeplerianOne(orbit);
78 final double meanMotion = keplerianOrbit.getKeplerianMeanMotion();
79 final double meanAnomaly = keplerianOrbit.getMeanAnomaly();
80 if (isForward) {
81 return computeKeplerianDurationToNextPeriapsis(meanAnomaly, meanMotion);
82 } else {
83 return computeKeplerianDurationFromPreviousPeriapsis(meanAnomaly, meanMotion);
84 }
85 };
86 }
87
88
89
90
91
92
93 public static AdaptableInterval getApoapsisDetectionAdaptableInterval() {
94 return (state, isForward) -> {
95 final Orbit orbit = state.getOrbit();
96 final KeplerianOrbit keplerianOrbit = convertOrbitIntoKeplerianOne(orbit);
97 final double meanMotion = keplerianOrbit.getKeplerianMeanMotion();
98 final double meanAnomaly = keplerianOrbit.getMeanAnomaly();
99 if (isForward) {
100 return computeKeplerianDurationToNextApoapsis(meanAnomaly, meanMotion);
101 }
102 else {
103 return computeKeplerianDurationFromPreviousApoapsis(meanAnomaly, meanMotion);
104 }
105 };
106 }
107
108
109
110
111
112
113 private static KeplerianOrbit convertOrbitIntoKeplerianOne(final Orbit orbit) {
114 return (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(orbit);
115 }
116
117
118
119
120
121
122
123 private static double computeKeplerianDurationToNextPeriapsis(final double meanAnomaly,
124 final double meanMotion) {
125 final double normalizedMeanAnomaly = MathUtils.normalizeAngle(meanAnomaly, FastMath.PI);
126 return (MathUtils.TWO_PI - normalizedMeanAnomaly) / meanMotion;
127 }
128
129
130
131
132
133
134
135 public static double computeKeplerianDurationFromPreviousPeriapsis(final double meanAnomaly,
136 final double meanMotion) {
137 final double normalizedMeanAnomaly = MathUtils.normalizeAngle(meanAnomaly, FastMath.PI);
138 return normalizedMeanAnomaly / meanMotion;
139 }
140
141
142
143
144
145
146
147 private static double computeKeplerianDurationToNextApoapsis(final double meanAnomaly,
148 final double meanMotion) {
149 final double normalizedMeanAnomaly = MathUtils.normalizeAngle(meanAnomaly, MathUtils.TWO_PI);
150 return (MathUtils.TWO_PI + FastMath.PI - normalizedMeanAnomaly) / meanMotion;
151 }
152
153
154
155
156
157
158
159 public static double computeKeplerianDurationFromPreviousApoapsis(final double meanAnomaly,
160 final double meanMotion) {
161 final double normalizedMeanAnomaly = MathUtils.normalizeAngle(meanAnomaly, MathUtils.TWO_PI);
162 return (normalizedMeanAnomaly - FastMath.PI) / meanMotion;
163 }
164 }