1   /* Copyright 2002-2026 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.bodies;
18  
19  import java.util.concurrent.TimeUnit;
20  
21  import org.hipparchus.CalculusFieldElement;
22  import org.hipparchus.geometry.euclidean.threed.FieldRotation;
23  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
24  import org.hipparchus.geometry.euclidean.threed.Rotation;
25  import org.hipparchus.geometry.euclidean.threed.RotationConvention;
26  import org.hipparchus.geometry.euclidean.threed.Vector3D;
27  import org.orekit.frames.FieldStaticTransform;
28  import org.orekit.frames.FieldTransform;
29  import org.orekit.frames.StaticTransform;
30  import org.orekit.frames.Transform;
31  import org.orekit.frames.TransformProvider;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.time.FieldAbsoluteDate;
34  import org.orekit.time.TimeOffset;
35  
36  /** Class for JPL body-fixed frame transform providers.
37   * @author Luc Maisonobe
38   * @author Romain Serra
39   * @since 13.1.8
40   */
41  class JPLRotatingTransformProvider implements TransformProvider {
42  
43      /** Time step for finite differences. */
44      private static final int DT = 10;
45  
46      /** IAU pole. */
47      private final IAUPole iauPole;
48  
49      /**
50       * Constructor.
51       * @param iauPole IAU pole
52       */
53      JPLRotatingTransformProvider(final IAUPole iauPole) {
54          this.iauPole       = iauPole;
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public Transform getTransform(final AbsoluteDate date) {
60          final TimeOffset dt = new TimeOffset(DT, TimeUnit.SECONDS);
61          final double w0 = iauPole.getPrimeMeridianAngle(date);
62          final double w1 = iauPole.getPrimeMeridianAngle(date.shiftedBy(dt));
63          return new Transform(date, new Rotation(Vector3D.PLUS_K, w0, RotationConvention.FRAME_TRANSFORM),
64                  new Vector3D((w1 - w0) / dt.toDouble(), Vector3D.PLUS_K));
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public StaticTransform getStaticTransform(final AbsoluteDate date) {
70          final double w0 = iauPole.getPrimeMeridianAngle(date);
71          return StaticTransform.of(date, new Rotation(Vector3D.PLUS_K, w0, RotationConvention.FRAME_TRANSFORM));
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
77          final TimeOffset dt = new TimeOffset(DT, TimeUnit.SECONDS);
78          final T w0 = iauPole.getPrimeMeridianAngle(date);
79          final T w1 = iauPole.getPrimeMeridianAngle(date.shiftedBy(dt));
80          return new FieldTransform<>(date,
81                  new FieldRotation<>(FieldVector3D.getPlusK(date.getField()), w0, RotationConvention.FRAME_TRANSFORM),
82                  new FieldVector3D<>(w1.subtract(w0).divide(dt.toDouble()), Vector3D.PLUS_K));
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public <T extends CalculusFieldElement<T>> FieldStaticTransform<T> getStaticTransform(final FieldAbsoluteDate<T> date) {
88          final T w0 = iauPole.getPrimeMeridianAngle(date);
89          return FieldStaticTransform.of(date,
90                  new FieldRotation<>(FieldVector3D.getPlusK(date.getField()), w0, RotationConvention.FRAME_TRANSFORM));
91      }
92  
93  }