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  
18  package org.orekit.utils;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.orekit.frames.Frame;
22  import org.orekit.frames.KinematicTransform;
23  import org.orekit.frames.StaticTransform;
24  import org.orekit.frames.Transform;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.TimeShiftable;
27  import org.orekit.time.TimeStamped;
28  
29  /** Interface for time-shiftable PV provider holding themselves PV coordinates.
30   * @author Romain Serra
31   * @since 13.1.2
32   */
33  public interface ShiftablePVCoordinatesHolder<T extends PVCoordinatesProvider>
34          extends PVCoordinatesProvider, TimeStamped, TimeShiftable<ShiftablePVCoordinatesHolder<T>> {
35  
36      /**
37       * Getter for the intrinsic position-velocity vector.
38       * @return position-velocity
39       */
40      TimeStampedPVCoordinates getPVCoordinates();
41  
42      /**
43       * Getter for the position vector.
44       * @return position
45       */
46      default Vector3D getPosition() {
47          return getPVCoordinates().getPosition();
48      }
49  
50      /**
51       * Getter for the velocity vector.
52       * @return velocity
53       */
54      default Vector3D getVelocity() {
55          return getPVCoordinates().getVelocity();
56      }
57  
58      /**
59       * Getter for the intrinsic frame.
60       * @return frame
61       */
62      Frame getFrame();
63  
64      @Override
65      default Vector3D getPosition(final AbsoluteDate date, final Frame frame) {
66          final ShiftablePVCoordinatesHolder<T> shifted = shiftedBy(date.durationFrom(getDate()));
67          final Vector3D position = shifted.getPosition();
68          if (frame ==  getFrame()) {
69              return position;
70          }
71          final StaticTransform staticTransform = shifted.getFrame().getStaticTransformTo(frame, date);
72          return staticTransform.transformPosition(position);
73      }
74  
75      @Override
76      default Vector3D getVelocity(final AbsoluteDate date, final Frame frame) {
77          final ShiftablePVCoordinatesHolder<T> shifted = shiftedBy(date.durationFrom(getDate()));
78          final TimeStampedPVCoordinates pv = shifted.getPVCoordinates();
79          if (frame ==  getFrame()) {
80              return pv.getVelocity();
81          }
82          final KinematicTransform kinematicTransform = shifted.getFrame().getKinematicTransformTo(frame, date);
83          final PVCoordinates transformedPV = kinematicTransform.transformOnlyPV(pv);
84          return transformedPV.getVelocity();
85      }
86  
87      @Override
88      default TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame) {
89          final ShiftablePVCoordinatesHolder<T> shifted = shiftedBy(date.durationFrom(getDate()));
90          final TimeStampedPVCoordinates pv = shifted.getPVCoordinates();
91          if (frame ==  getFrame()) {
92              return pv;
93          }
94          final Transform transform = getFrame().getTransformTo(frame, date);
95          return transform.transformPVCoordinates(pv);
96      }
97  }