AngularSeparationFromSatelliteDetector.java

  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. 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 two moving objects come close to each other, as seen from spacecraft.
  26.  * <p>The main use case for this detector is when the primary object is in fact a ground
  27.  * station, modeled as a {@link org.orekit.frames.TopocentricFrame} and when the secondary
  28.  * is the {@link CelestialBodies#getSun() Sun}, for computing
  29.  * optical reflections.</p>
  30.  * <p>The default handler behavior is to {@link Action#STOP stop}
  31.  * propagation when objects enter the proximity zone. This can be changed by calling
  32.  * {@link #withHandler(EventHandler)} after construction.</p>
  33.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  34.  * @author Luc Maisonobe
  35.  * @author Thomas Paulet
  36.  * @since 11.0
  37.  */
  38. public class AngularSeparationFromSatelliteDetector extends AbstractDetector<AngularSeparationFromSatelliteDetector> {

  39.     /** Primary object, at the center of the proximity zone. */
  40.     private final PVCoordinatesProvider primaryObject;

  41.     /** Secondary object, that may come close to the primary, as seen from the spacecraft . */
  42.     private final PVCoordinatesProvider secondaryObject;

  43.     /** Proximity angle (rad). */
  44.     private final double proximityAngle;

  45.     /** Build a new angular detachment detector.
  46.      * @param primaryObject primaryObject, at the center of the proximity zone
  47.      * @param secondaryObject secondaryObject, that may come close to
  48.      *        the primaryObject as seen from the spacecraft
  49.      * @param proximityAngle proximity angle as seen from spacecraft, at which events are triggered (rad)
  50.      */
  51.     public AngularSeparationFromSatelliteDetector(final PVCoordinatesProvider primaryObject,
  52.                                                   final PVCoordinatesProvider secondaryObject,
  53.                                                   final double proximityAngle) {
  54.         this(EventDetectionSettings.getDefaultEventDetectionSettings(), new StopOnDecreasing(),
  55.              primaryObject, secondaryObject, proximityAngle);
  56.     }

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

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

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

  94.     /** Get the secondaryObject.
  95.      * @return secondaryObject
  96.      */
  97.     public PVCoordinatesProvider getSecondaryObject() {
  98.         return secondaryObject;
  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 primary and secondary objects
  109.      * as seen from the spacecraft minus the proximity angle. It therefore triggers
  110.      * decreasing events when the secondary object 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 secondary object is behind the primary.
  116.      * 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 eclipse conditions.
  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 primaryPos   = primaryObject  .getPosition(s.getDate(), s.getFrame());
  126.         final Vector3D secondaryPos = secondaryObject.getPosition(s.getDate(), s.getFrame());
  127.         final double separation = Vector3D.angle(primaryPos.subtract(sPosition),
  128.                                                  secondaryPos.subtract(sPosition));
  129.         return separation - proximityAngle;
  130.     }

  131. }