1 /* Copyright 2020-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.bodies.CelestialBodies;
22 import org.orekit.propagation.SpacecraftState;
23 import org.orekit.propagation.events.handlers.EventHandler;
24 import org.orekit.propagation.events.handlers.StopOnDecreasing;
25 import org.orekit.utils.PVCoordinates;
26 import org.orekit.utils.PVCoordinatesProvider;
27
28 /** Detects when two moving objects come close to each other, as seen from spacecraft.
29 * <p>The main use case for this detector is when the primary object is in fact a ground
30 * station, modeled as a {@link org.orekit.frames.TopocentricFrame} and when the secondary
31 * is the {@link CelestialBodies#getSun() Sun}, for computing
32 * optical reflections.</p>
33 * <p>The default handler behavior is to {@link Action#STOP stop}
34 * propagation when objects enter the proximity zone. This can be changed by calling
35 * {@link #withHandler(EventHandler)} after construction.</p>
36 * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
37 * @author Luc Maisonobe
38 * @author Thomas Paulet
39 * @since 11.0
40 */
41 public class AngularSeparationFromSatelliteDetector extends AbstractDetector<AngularSeparationFromSatelliteDetector> {
42
43 /** Primary object, at the center of the proximity zone. */
44 private final PVCoordinatesProvider primaryObject;
45
46 /** Secondary object, that may come close to the primary, as seen from the spacecraft . */
47 private final PVCoordinatesProvider secondaryObject;
48
49 /** Proximity angle (rad). */
50 private final double proximityAngle;
51
52 /** Build a new angular detachment detector.
53 * @param primaryObject primaryObject, at the center of the proximity zone
54 * @param secondaryObject secondaryObject, that may come close to
55 * the primaryObject as seen from the spacecraft
56 * @param proximityAngle proximity angle as seen from spacecraft, at which events are triggered (rad)
57 */
58 public AngularSeparationFromSatelliteDetector(final PVCoordinatesProvider primaryObject,
59 final PVCoordinatesProvider secondaryObject,
60 final double proximityAngle) {
61 this(EventDetectionSettings.getDefaultEventDetectionSettings(), new StopOnDecreasing(),
62 primaryObject, secondaryObject, proximityAngle);
63 }
64
65 /** Protected constructor with full parameters.
66 * <p>
67 * This constructor is not public as users are expected to use the builder
68 * API with the various {@code withXxx()} methods to set up the instance
69 * in a readable manner without using a huge amount of parameters.
70 * </p>
71 * @param detectionSettings detection Settings
72 * @param handler event handler to call at event occurrences
73 * @param primaryObject primaryObject at the center of the proximity zone
74 * @param secondaryObject secondaryObject, that may come close to
75 * the primaryObject as seen from the spacecraft
76 * @param proximityAngle proximity angle as seen from secondaryObject, at which events are triggered (rad)
77 * @since 13.0
78 */
79 protected AngularSeparationFromSatelliteDetector(final EventDetectionSettings detectionSettings,
80 final EventHandler handler,
81 final PVCoordinatesProvider primaryObject,
82 final PVCoordinatesProvider secondaryObject,
83 final double proximityAngle) {
84 super(detectionSettings, handler);
85 this.primaryObject = primaryObject;
86 this.secondaryObject = secondaryObject;
87 this.proximityAngle = proximityAngle;
88 }
89
90 /** {@inheritDoc} */
91 @Override
92 protected AngularSeparationFromSatelliteDetector create(final EventDetectionSettings detectionSettings,
93 final EventHandler newHandler) {
94 return new AngularSeparationFromSatelliteDetector(detectionSettings, newHandler,
95 primaryObject, secondaryObject, proximityAngle);
96 }
97
98 /** Get the primaryObject, at the center of the proximity zone.
99 * @return primaryObject
100 */
101 public PVCoordinatesProvider getPrimaryObject() {
102 return primaryObject;
103 }
104
105 /** Get the secondaryObject.
106 * @return secondaryObject
107 */
108 public PVCoordinatesProvider getSecondaryObject() {
109 return secondaryObject;
110 }
111
112 /** Get the proximity angle (rad).
113 * @return the proximity angle
114 */
115 public double getProximityAngle() {
116 return proximityAngle;
117 }
118
119 /** Compute the value of the switching function.
120 * <p>
121 * This function measures the angular separation between primary and secondary objects
122 * as seen from the spacecraft minus the proximity angle. It therefore triggers
123 * decreasing events when the secondary object enters the proximity zone and increasing
124 * events when it leaves the proximity zone.
125 * </p>
126 * <p>
127 * No shadowing effect is taken into account, so this method is computed and
128 * may trigger events even when the secondary object is behind the primary.
129 * If such effects must be taken into account the
130 * detector must be associated with a {@link EventEnablingPredicateFilter predicate
131 * filter} where the {@link EnablingPredicate predicate function} is based on eclipse conditions.
132 * </p>
133 * @param s the current state information: date, kinematics, attitude
134 * @return value of the switching function
135 */
136 public double g(final SpacecraftState s) {
137 final PVCoordinates sPV = s.getPVCoordinates();
138 final Vector3D primaryPos = primaryObject .getPosition(s.getDate(), s.getFrame());
139 final Vector3D secondaryPos = secondaryObject.getPosition(s.getDate(), s.getFrame());
140 final double separation = Vector3D.angle(primaryPos.subtract(sPV.getPosition()),
141 secondaryPos.subtract(sPV.getPosition()));
142 return separation - proximityAngle;
143 }
144
145 }