AngularSeparationDetector.java

  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. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.ode.events.Action;
  20. import org.orekit.bodies.CelestialBodies;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  24. import org.orekit.utils.PVCoordinatesProvider;

  25. /** Detects when spacecraft comes close to a moving beacon, as seen from a moving observer.
  26.  * <p>The main use case for this detector is when the observer is in fact a ground
  27.  * station, modeled as a {@link org.orekit.frames.TopocentricFrame} and when the beacon
  28.  * is the {@link CelestialBodies#getSun() Sun}, for computing
  29.  * interferences for the telemetry link. Another similar case is when the beacon is
  30.  * another spacecraft, for interferences computation.</p>
  31.  * <p>The default handler behavior is to {@link Action#STOP stop}
  32.  * propagation when spacecraft enters the proximity zone. This can be changed by calling
  33.  * {@link #withHandler(EventHandler)} after construction.</p>
  34.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  35.  * @author Luc Maisonobe
  36.  * @since 8.0
  37.  */
  38. public class AngularSeparationDetector extends AbstractDetector<AngularSeparationDetector> {

  39.     /** Default detection settings. */
  40.     public static final EventDetectionSettings DEFAULT_SETTINGS = new EventDetectionSettings(60., 1e-3, EventDetectionSettings.DEFAULT_MAX_ITER);

  41.     /** Beacon at the center of the proximity zone. */
  42.     private final PVCoordinatesProvider beacon;

  43.     /** Observer for the spacecraft, that may also see the beacon at the same time if they are too close. */
  44.     private final PVCoordinatesProvider observer;

  45.     /** Proximity angle (rad). */
  46.     private final double proximityAngle;

  47.     /** Build a new angular separation detector.
  48.      * @param beacon beacon at the center of the proximity zone
  49.      * @param observer observer for the spacecraft, that may also see
  50.      * the beacon at the same time if they are too close to each other
  51.      * @param proximityAngle proximity angle as seen from observer, at which events are triggered (rad)
  52.      */
  53.     public AngularSeparationDetector(final PVCoordinatesProvider beacon,
  54.                                      final PVCoordinatesProvider observer,
  55.                                      final double proximityAngle) {
  56.         this(DEFAULT_SETTINGS, new StopOnDecreasing(), beacon, observer, proximityAngle);
  57.     }

  58.     /** Protected constructor with full parameters.
  59.      * <p>
  60.      * This constructor is not public as users are expected to use the builder
  61.      * API with the various {@code withXxx()} methods to set up the instance
  62.      * in a readable manner without using a huge amount of parameters.
  63.      * </p>
  64.      * @param detectionSettings detection settings
  65.      * @param handler event handler to call at event occurrences
  66.      * @param beacon beacon at the center of the proximity zone
  67.      * @param observer observer for the spacecraft, that may also see
  68.      * the beacon at the same time if they are too close to each other
  69.      * @param proximityAngle proximity angle as seen from observer, at which events are triggered (rad)
  70.      * @since 13.0
  71.      */
  72.     protected AngularSeparationDetector(final EventDetectionSettings detectionSettings,
  73.                                         final EventHandler handler,
  74.                                         final PVCoordinatesProvider beacon,
  75.                                         final PVCoordinatesProvider observer,
  76.                                         final double proximityAngle) {
  77.         super(detectionSettings, handler);
  78.         this.beacon         = beacon;
  79.         this.observer       = observer;
  80.         this.proximityAngle = proximityAngle;
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     protected AngularSeparationDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  85.         return new AngularSeparationDetector(detectionSettings, newHandler,
  86.                                              beacon, observer, proximityAngle);
  87.     }

  88.     /** Get the beacon at the center of the proximity zone.
  89.      * @return beacon at the center of the proximity zone
  90.      */
  91.     public PVCoordinatesProvider getBeacon() {
  92.         return beacon;
  93.     }

  94.     /** Get the observer for the spacecraft.
  95.      * @return observer for the spacecraft
  96.      */
  97.     public PVCoordinatesProvider getObserver() {
  98.         return observer;
  99.     }

  100.     /** Get the proximity angle (rad).
  101.      * @return the proximity angle
  102.      */
  103.     public double getProximityAngle() {
  104.         return proximityAngle;
  105.     }

  106.     /** Compute the value of the switching function.
  107.      * <p>
  108.      * This function measures the angular separation between beacon and spacecraft
  109.      * as seen from the observer minus the proximity angle. It therefore triggers
  110.      * decreasing events when the spacecraft enters the proximity zone and increasing
  111.      * events when it leaves the proximity zone.
  112.      * </p>
  113.      * <p>
  114.      * No shadowing effect is taken into account, so this method is computed and
  115.      * may trigger events even when the spacecraft is below horizon for an observer
  116.      * which is a ground station. If such effects must be taken into account the
  117.      * detector must be associated with a {@link EventEnablingPredicateFilter predicate
  118.      * filter} where the {@link EnablingPredicate predicate function} is based on elevation.
  119.      * </p>
  120.      * @param s the current state information: date, kinematics, attitude
  121.      * @return value of the switching function
  122.      */
  123.     public double g(final SpacecraftState s) {
  124.         final Vector3D sPosition = s.getPosition();
  125.         final Vector3D bP = beacon.getPosition(s.getDate(), s.getFrame());
  126.         final Vector3D oP = observer.getPosition(s.getDate(), s.getFrame());
  127.         final double separation = Vector3D.angle(sPosition.subtract(oP), bP.subtract(oP));
  128.         return separation - proximityAngle;
  129.     }

  130. }