FieldExtremumAngularSeparationDetector.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.CalculusFieldElement;
  19. import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative1;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.orekit.propagation.FieldSpacecraftState;
  22. import org.orekit.propagation.events.handlers.FieldEventHandler;
  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 FieldAngularSeparationDetector
  29.  * @since 13.1
  30.  */
  31. public class FieldExtremumAngularSeparationDetector<T extends CalculusFieldElement<T>>
  32.         extends FieldAbstractDetector<FieldExtremumAngularSeparationDetector<T>, T> {

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

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

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

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     protected FieldExtremumAngularSeparationDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  55.                                                                final FieldEventHandler<T> newHandler) {
  56.         return new FieldExtremumAngularSeparationDetector<>(detectionSettings, newHandler, beacon, observer);
  57.     }

  58.     /** Get the beacon at the center of the proximity zone.
  59.      * @return beacon at the center of the proximity zone
  60.      */
  61.     public ExtendedPositionProvider getBeacon() {
  62.         return beacon;
  63.     }

  64.     /** Get the observer for the spacecraft.
  65.      * @return observer for the spacecraft
  66.      */
  67.     public ExtendedPositionProvider getObserver() {
  68.         return observer;
  69.     }

  70.     @Override
  71.     public T g(final FieldSpacecraftState<T> s) {
  72.         final FieldPVCoordinates<FieldUnivariateDerivative1<T>> pv = s.getPVCoordinates().toUnivariateDerivative1PV();
  73.         final FieldAbsoluteDate<FieldUnivariateDerivative1<T>> fieldDate = s.getDate().toFUD1Field();
  74.         final FieldVector3D<FieldUnivariateDerivative1<T>> bP = beacon.getPosition(fieldDate, s.getFrame());
  75.         final FieldVector3D<FieldUnivariateDerivative1<T>> oP = observer.getPosition(fieldDate, s.getFrame());
  76.         final FieldUnivariateDerivative1<T> separation = FieldVector3D.angle(pv.getPosition().subtract(oP), bP.subtract(oP));
  77.         return separation.getFirstDerivative();
  78.     }

  79. }