1   /* Copyright 2022-2025 Luc Maisonobe
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.attitudes;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative2;
21  import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
22  import org.hipparchus.analysis.differentiation.UnivariateDerivative2Field;
23  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
24  import org.hipparchus.geometry.euclidean.threed.Vector3D;
25  import org.orekit.bodies.OneAxisEllipsoid;
26  import org.orekit.frames.Frame;
27  import org.orekit.time.FieldAbsoluteDate;
28  import org.orekit.utils.ExtendedPositionProvider;
29  import org.orekit.utils.FieldPVCoordinates;
30  import org.orekit.utils.TimeStampedFieldPVCoordinates;
31  import org.orekit.utils.TimeStampedPVCoordinates;
32  
33  /**
34   * Provider for target vector.
35   * @author Luc Maisonobe
36   * @since 12.2
37   */
38  public interface TargetProvider
39  {
40  
41      /**
42       * Get a target vector.
43       * @param sun   Sun model
44       * @param earth Earth model
45       * @param pv    spacecraft position and velocity
46       * @param frame inertial frame
47       * @return target direction in the spacecraft state frame, with second order time derivative
48       */
49      default FieldVector3D<UnivariateDerivative2> getDerivative2TargetDirection(ExtendedPositionProvider sun,
50                                                                                 OneAxisEllipsoid earth,
51                                                                                 TimeStampedPVCoordinates pv,
52                                                                                 Frame frame) {
53          final FieldPVCoordinates<UnivariateDerivative2> ud2PV = pv.toUnivariateDerivative2PV();
54          final UnivariateDerivative2Field field = UnivariateDerivative2Field.getInstance();
55          final UnivariateDerivative2 dt = new UnivariateDerivative2(0., 1., 0.);
56          final FieldAbsoluteDate<UnivariateDerivative2> ud2Date = new FieldAbsoluteDate<>(field, pv.getDate()).shiftedBy(dt);
57          return getTargetDirection(sun, earth, new TimeStampedFieldPVCoordinates<>(ud2Date, ud2PV), frame);
58      }
59  
60      /**
61       * Get a target vector.
62       * @param sun   Sun model
63       * @param earth Earth model
64       * @param pv    spacecraft position and velocity
65       * @param frame inertial frame
66       * @return target direction in the spacecraft state frame
67       */
68      default Vector3D getTargetDirection(ExtendedPositionProvider sun, OneAxisEllipsoid earth,
69                                          TimeStampedPVCoordinates pv, Frame frame) {
70          return getDerivative2TargetDirection(sun, earth, pv, frame).toVector3D();
71      }
72  
73      /**
74       * Get a target vector.
75       * @param <T>   type of the field element
76       * @param sun   Sun model
77       * @param earth Earth model
78       * @param pv    spacecraft position and velocity
79       * @param frame inertial frame
80       * @return target direction in the spacecraft state frame, with second order time derivative
81       */
82      default <T extends CalculusFieldElement<T>> FieldVector3D<FieldUnivariateDerivative2<T>> getDerivative2TargetDirection(ExtendedPositionProvider sun,
83                                                                                                                             OneAxisEllipsoid earth,
84                                                                                                                             TimeStampedFieldPVCoordinates<T> pv,
85                                                                                                                             Frame frame) {
86          final FieldPVCoordinates<FieldUnivariateDerivative2<T>> ud2PV = pv.toUnivariateDerivative2PV();
87          final FieldAbsoluteDate<FieldUnivariateDerivative2<T>> ud2Date = pv.getDate().toFUD2Field();
88          return getTargetDirection(sun, earth, new TimeStampedFieldPVCoordinates<>(ud2Date, ud2PV), frame);
89      }
90  
91      /**
92       * Get a target vector.
93       * @param <T>   type of the field element
94       * @param sun   Sun model
95       * @param earth Earth model
96       * @param pv    spacecraft position and velocity
97       * @param frame inertial frame
98       * @return target direction in the spacecraft state frame
99       */
100     <T extends CalculusFieldElement<T>> FieldVector3D<T> getTargetDirection(ExtendedPositionProvider sun,
101                                                                             OneAxisEllipsoid earth,
102                                                                             TimeStampedFieldPVCoordinates<T> pv,
103                                                                             Frame frame);
104 }