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.PVCoordinates;
  25. import org.orekit.utils.PVCoordinatesProvider;

  26. /** Detects when two moving objects come close to each other, as seen from spacecraft.
  27.  * <p>The main use case for this detector is when the primary object is in fact a ground
  28.  * station, modeled as a {@link org.orekit.frames.TopocentricFrame} and when the secondary
  29.  * is the {@link CelestialBodies#getSun() Sun}, for computing
  30.  * optical reflections.</p>
  31.  * <p>The default handler behavior is to {@link Action#STOP stop}
  32.  * propagation when objects enter 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.  * @author Thomas Paulet
  37.  * @since 11.0
  38.  */
  39. public class AngularSeparationFromSatelliteDetector extends AbstractDetector<AngularSeparationFromSatelliteDetector> {

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

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

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

  46.     /** Build a new angular detachment detector.
  47.      * @param primaryObject primaryObject, at the center of the proximity zone
  48.      * @param secondaryObject secondaryObject, that may come close to
  49.      *        the primaryObject as seen from the spacecraft
  50.      * @param proximityAngle proximity angle as seen from spacecraft, at which events are triggered (rad)
  51.      */
  52.     public AngularSeparationFromSatelliteDetector(final PVCoordinatesProvider primaryObject,
  53.                                                   final PVCoordinatesProvider secondaryObject,
  54.                                                   final double proximityAngle) {
  55.         this(EventDetectionSettings.getDefaultEventDetectionSettings(), new StopOnDecreasing(),
  56.              primaryObject, secondaryObject, 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 primaryObject primaryObject at the center of the proximity zone
  67.      * @param secondaryObject secondaryObject, that may come close to
  68.      *        the primaryObject as seen from the spacecraft
  69.      * @param proximityAngle proximity angle as seen from secondaryObject, at which events are triggered (rad)
  70.      * @since 13.0
  71.      */
  72.     protected AngularSeparationFromSatelliteDetector(final EventDetectionSettings detectionSettings,
  73.                                                      final EventHandler handler,
  74.                                                      final PVCoordinatesProvider primaryObject,
  75.                                                      final PVCoordinatesProvider secondaryObject,
  76.                                                      final double proximityAngle) {
  77.         super(detectionSettings, handler);
  78.         this.primaryObject         = primaryObject;
  79.         this.secondaryObject       = secondaryObject;
  80.         this.proximityAngle = proximityAngle;
  81.     }

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

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

  95.     /** Get the secondaryObject.
  96.      * @return secondaryObject
  97.      */
  98.     public PVCoordinatesProvider getSecondaryObject() {
  99.         return secondaryObject;
  100.     }

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

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

  132. }