1   /* Copyright 2002-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.attitudes;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.orekit.bodies.BodyShape;
23  import org.orekit.bodies.GeodeticPoint;
24  import org.orekit.frames.FieldStaticTransform;
25  import org.orekit.frames.FieldTransform;
26  import org.orekit.frames.Frame;
27  import org.orekit.frames.StaticTransform;
28  import org.orekit.frames.Transform;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.time.FieldAbsoluteDate;
31  import org.orekit.utils.FieldPVCoordinatesProvider;
32  import org.orekit.utils.PVCoordinatesProvider;
33  import org.orekit.utils.TimeStampedFieldPVCoordinates;
34  import org.orekit.utils.TimeStampedPVCoordinates;
35  
36  /**
37   * This class handles target pointing attitude provider.
38  
39   * <p>
40   * This class represents the attitude provider where the satellite z axis is
41   * pointing to a ground point target.</p>
42   * <p>
43   * The target position is defined in a body frame specified by the user.
44   * It is important to make sure this frame is consistent.
45   * </p>
46   * <p>
47   * The object <code>TargetPointing</code> is guaranteed to be immutable.
48   * </p>
49   * @see     GroundPointing
50   * @author V&eacute;ronique Pommier-Maurussane
51   */
52  public class TargetPointing extends GroundPointing {
53  
54      /** Target in body frame. */
55      private final Vector3D target;
56  
57      /** Creates a new instance from body frame and target expressed in Cartesian coordinates.
58       * @param inertialFrame frame in which orbital velocities are computed
59       * @param bodyFrame body frame.
60       * @param target target position in body frame
61       * @since 7.1
62       */
63      public TargetPointing(final Frame inertialFrame, final Frame bodyFrame, final Vector3D target) {
64          super(inertialFrame, bodyFrame);
65          this.target = target;
66      }
67  
68      /** Creates a new instance from body shape and target expressed in geodetic coordinates.
69       * @param inertialFrame frame in which orbital velocities are computed
70       * @param targetGeo target defined as a geodetic point in body shape frame
71       * @param shape body shape
72       * @since 7.1
73       */
74      public TargetPointing(final Frame inertialFrame, final GeodeticPoint targetGeo, final BodyShape shape) {
75          super(inertialFrame, shape.getBodyFrame());
76          // Transform target from geodetic coordinates to Cartesian coordinates
77          target = shape.transform(targetGeo);
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public TimeStampedPVCoordinates getTargetPV(final PVCoordinatesProvider pvProv,
83                                                  final AbsoluteDate date, final Frame frame) {
84          final Transform t = getBodyFrame().getTransformTo(frame, date);
85          final TimeStampedPVCoordinates pv =
86                  new TimeStampedPVCoordinates(date, target, Vector3D.ZERO, Vector3D.ZERO);
87          return t.transformPVCoordinates(pv);
88      }
89  
90      /** {@inheritDoc} */
91      @Override
92      protected Vector3D getTargetPosition(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) {
93          final StaticTransform staticTransform = getBodyFrame().getStaticTransformTo(frame, date);
94          return staticTransform.transformPosition(target);
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T> getTargetPV(final FieldPVCoordinatesProvider<T> pvProv,
100                                                                                             final FieldAbsoluteDate<T> date, final Frame frame) {
101         final FieldTransform<T> t = getBodyFrame().getTransformTo(frame, date);
102         final FieldVector3D<T> zero = FieldVector3D.getZero(date.getField());
103         final TimeStampedFieldPVCoordinates<T> pv =
104                 new TimeStampedFieldPVCoordinates<>(date, new FieldVector3D<>(date.getField(), target), zero, zero);
105         return t.transformPVCoordinates(pv);
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getTargetPosition(final FieldPVCoordinatesProvider<T> pvProv,
111                                                                                      final FieldAbsoluteDate<T> date,
112                                                                                      final Frame frame) {
113         final FieldStaticTransform<T> staticTransform = getBodyFrame().getStaticTransformTo(frame, date);
114         return staticTransform.transformPosition(target);
115     }
116 }