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  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative1;
21  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
22  import org.orekit.propagation.FieldSpacecraftState;
23  import org.orekit.propagation.events.handlers.FieldEventHandler;
24  import org.orekit.time.FieldAbsoluteDate;
25  import org.orekit.utils.ExtendedPositionProvider;
26  import org.orekit.utils.FieldPVCoordinates;
27  
28  /** Detector of local extrema with angular separation.
29   * @author Romain Serra
30   * @see FieldAngularSeparationDetector
31   * @since 13.1
32   */
33  public class FieldExtremumAngularSeparationDetector<T extends CalculusFieldElement<T>>
34          extends FieldAbstractDetector<FieldExtremumAngularSeparationDetector<T>, T> {
35  
36      /** Beacon at the center of the proximity zone. */
37      private final ExtendedPositionProvider beacon;
38  
39      /** Observer for the spacecraft, that may also see the beacon at the same time if they are too close. */
40      private final ExtendedPositionProvider observer;
41  
42      /** Protected constructor with full parameters.
43       * @param detectionSettings detection settings
44       * @param handler event handler to call at event occurrences
45       * @param beacon beacon at the center of the proximity zone
46       * @param observer observer for the spacecraft, that may also see
47       * the beacon at the same time if they are too close to each other
48       */
49      public FieldExtremumAngularSeparationDetector(final FieldEventDetectionSettings<T> detectionSettings,
50                                                       final FieldEventHandler<T> handler,
51                                                       final ExtendedPositionProvider beacon,
52                                                       final ExtendedPositionProvider observer) {
53          super(detectionSettings, handler);
54          this.beacon         = beacon;
55          this.observer       = observer;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      protected FieldExtremumAngularSeparationDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
61                                                                 final FieldEventHandler<T> newHandler) {
62          return new FieldExtremumAngularSeparationDetector<>(detectionSettings, newHandler, beacon, observer);
63      }
64  
65      /** Get the beacon at the center of the proximity zone.
66       * @return beacon at the center of the proximity zone
67       */
68      public ExtendedPositionProvider getBeacon() {
69          return beacon;
70      }
71  
72      /** Get the observer for the spacecraft.
73       * @return observer for the spacecraft
74       */
75      public ExtendedPositionProvider getObserver() {
76          return observer;
77      }
78  
79      @Override
80      public T g(final FieldSpacecraftState<T> s) {
81          final FieldPVCoordinates<FieldUnivariateDerivative1<T>> pv = s.getPVCoordinates().toUnivariateDerivative1PV();
82          final FieldAbsoluteDate<FieldUnivariateDerivative1<T>> fieldDate = s.getDate().toFUD1Field();
83          final FieldVector3D<FieldUnivariateDerivative1<T>> bP = beacon.getPosition(fieldDate, s.getFrame());
84          final FieldVector3D<FieldUnivariateDerivative1<T>> oP = observer.getPosition(fieldDate, s.getFrame());
85          final FieldUnivariateDerivative1<T> separation = FieldVector3D.angle(pv.getPosition().subtract(oP), bP.subtract(oP));
86          return separation.getFirstDerivative();
87      }
88  
89  }