ExtremumAngularSeparationDetector.java

  1. /* Copyright 2022-2025 Romain Serra
  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.analysis.differentiation.UnivariateDerivative1;
  19. import org.hipparchus.analysis.differentiation.UnivariateDerivative1Field;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.time.FieldAbsoluteDate;
  24. import org.orekit.utils.ExtendedPositionProvider;
  25. import org.orekit.utils.FieldPVCoordinates;

  26. /** Detector of local extrema with angular separation.
  27.  * @author Romain Serra
  28.  * @see AngularSeparationDetector
  29.  * @since 13.1
  30.  */
  31. public class ExtremumAngularSeparationDetector extends AbstractDetector<ExtremumAngularSeparationDetector> {

  32.     /** Beacon at the center of the proximity zone. */
  33.     private final ExtendedPositionProvider beacon;

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

  36.     /** Protected constructor with full parameters.
  37.      * @param detectionSettings detection settings
  38.      * @param handler event handler to call at event occurrences
  39.      * @param beacon beacon at the center of the proximity zone
  40.      * @param observer observer for the spacecraft, that may also see
  41.      * the beacon at the same time if they are too close to each other
  42.      */
  43.     public ExtremumAngularSeparationDetector(final EventDetectionSettings detectionSettings,
  44.                                              final EventHandler handler,
  45.                                              final ExtendedPositionProvider beacon,
  46.                                                 final ExtendedPositionProvider observer) {
  47.         super(detectionSettings, handler);
  48.         this.beacon         = beacon;
  49.         this.observer       = observer;
  50.     }

  51.     /** Get the beacon at the center of the proximity zone.
  52.      * @return beacon at the center of the proximity zone
  53.      */
  54.     public ExtendedPositionProvider getBeacon() {
  55.         return beacon;
  56.     }

  57.     /** Get the observer for the spacecraft.
  58.      * @return observer for the spacecraft
  59.      */
  60.     public ExtendedPositionProvider getObserver() {
  61.         return observer;
  62.     }

  63.     @Override
  64.     protected ExtremumAngularSeparationDetector create(final EventDetectionSettings detectionSettings,
  65.                                                        final EventHandler newHandler) {
  66.         return new ExtremumAngularSeparationDetector(detectionSettings, newHandler, beacon, observer);
  67.     }

  68.     @Override
  69.     public double g(final SpacecraftState s) {
  70.         final FieldPVCoordinates<UnivariateDerivative1> pv = s.getPVCoordinates().toUnivariateDerivative1PV();
  71.         final UnivariateDerivative1 dt = new UnivariateDerivative1(0., 1.);
  72.         final FieldAbsoluteDate<UnivariateDerivative1> fieldDate = new FieldAbsoluteDate<>(UnivariateDerivative1Field.getInstance(),
  73.                 s.getDate()).shiftedBy(dt);
  74.         final FieldVector3D<UnivariateDerivative1> bP = beacon.getPosition(fieldDate, s.getFrame());
  75.         final FieldVector3D<UnivariateDerivative1> oP = observer.getPosition(fieldDate, s.getFrame());
  76.         final UnivariateDerivative1 separation = FieldVector3D.angle(pv.getPosition().subtract(oP), bP.subtract(oP));
  77.         return separation.getFirstDerivative();
  78.     }
  79. }