1   /* Contributed in the public domain.
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.frames;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.orekit.files.ccsds.definitions.ModifiedFrame;
21  import org.orekit.time.AbsoluteDate;
22  import org.orekit.time.FieldAbsoluteDate;
23  import org.orekit.utils.ExtendedPositionProvider;
24  
25  /**
26   * Transform provider that shifts the origin and keeps the orientation of
27   * another {@link Frame}.
28   *
29   * @author Evan M. Ward
30   * @see ModifiedFrame
31   * @see AngularTransformProvider
32   * @since 14.0
33   */
34  public class OriginTransformProvider implements TransformProvider {
35  
36      /** The new origin. */
37      private final ExtendedPositionProvider origin;
38  
39      /** The original frame, specifying the orientation. */
40      private final Frame frame;
41  
42      /**
43       * Create a transform provider to change the origin of an existing frame.
44       *
45       * @param frame  the existing frame that specifies the orientation.
46       * @param origin the new origin.
47       */
48      public OriginTransformProvider(final ExtendedPositionProvider origin,
49                                     final Frame frame) {
50          this.origin = origin;
51          this.frame = frame;
52      }
53  
54      @Override
55      public Transform getTransform(final AbsoluteDate date) {
56          return new Transform(date, origin.getPVCoordinates(date, frame).negate());
57      }
58  
59      @Override
60      public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(
61              final FieldAbsoluteDate<T> date) {
62          return new FieldTransform<>(
63                  date,
64                  origin.getPVCoordinates(date, frame).negate());
65      }
66  
67      @Override
68      public KinematicTransform getKinematicTransform(final AbsoluteDate date) {
69          return KinematicTransform
70                  .of(date, origin.getPVCoordinates(date, frame).negate());
71      }
72  
73      @Override
74      public <T extends CalculusFieldElement<T>> FieldKinematicTransform<T>
75          getKinematicTransform(final FieldAbsoluteDate<T> date) {
76  
77          return FieldKinematicTransform
78                  .of(date, origin.getPVCoordinates(date, frame).negate());
79      }
80  
81      @Override
82      public StaticTransform getStaticTransform(final AbsoluteDate date) {
83          return StaticTransform
84                  .of(date, origin.getPosition(date, frame).negate());
85      }
86  
87      @Override
88      public <T extends CalculusFieldElement<T>> FieldStaticTransform<T>
89          getStaticTransform(final FieldAbsoluteDate<T> date) {
90  
91          return FieldStaticTransform
92                  .of(date, origin.getPosition(date, frame).negate());
93      }
94  }