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.hipparchus.geometry.euclidean.threed.FieldRotation;
21  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
22  import org.hipparchus.geometry.euclidean.threed.Rotation;
23  import org.hipparchus.geometry.euclidean.threed.RotationConvention;
24  import org.hipparchus.geometry.euclidean.threed.Vector3D;
25  import org.orekit.annotation.DefaultDataContext;
26  import org.orekit.data.DataContext;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.time.FieldAbsoluteDate;
29  import org.orekit.time.TimeScalarFunction;
30  import org.orekit.time.TimeScales;
31  import org.orekit.utils.IERSConventions;
32  
33  /**
34   * An inertial frame aligned with the ecliptic.
35   * <p>
36   * The IAU defines the ecliptic as "the plane perpendicular to the mean heliocentric
37   * orbital angular momentum vector of the Earth-Moon barycentre in the BCRS (IAU 2006
38   * Resolution B1)." The +z axis is aligned with the angular momentum vector, and the +x
39   * axis is aligned with +x axis of {@link Frames#getMOD(IERSConventions) MOD}.
40   * </p>
41   *
42   * <p>
43   * This implementation agrees with the JPL 406 ephemerides to within 0.5 arc seconds.
44   * </p>
45   *
46   * @since 7.0
47   */
48  public class EclipticProvider implements TransformProvider {
49  
50      /** the obliquity of the ecliptic, in radians as a function of time. */
51      private final TimeScalarFunction obliquity;
52  
53      /**
54       * Create a transform provider from MOD to an ecliptically aligned frame.
55       *
56       * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
57       *
58       * @param conventions IERS conventions
59       * @see #EclipticProvider(IERSConventions, TimeScales)
60       */
61      @DefaultDataContext
62      public EclipticProvider(final IERSConventions conventions) {
63          this(conventions, DataContext.getDefault().getTimeScales());
64      }
65  
66      /**
67       * Create a transform provider from MOD to an ecliptically aligned frame.
68       * @param conventions IERS conventions
69       * @param timeScales to use in computing the transformation.
70       * @since 10.1
71       */
72      public EclipticProvider(final IERSConventions conventions,
73                              final TimeScales timeScales) {
74          this.obliquity   = conventions.getMeanObliquityFunction(timeScales);
75      }
76  
77      @Override
78      public Transform getTransform(final AbsoluteDate date) {
79          //mean obliquity of date
80          final double epsA = obliquity.value(date);
81          return new Transform(date, new Rotation(Vector3D.MINUS_I, epsA, RotationConvention.VECTOR_OPERATOR));
82      }
83  
84      @Override
85      public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
86          //mean obliquity of date
87          final T epsA = obliquity.value(date);
88          return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getMinusI(date.getField()),
89                                                                epsA,
90                                                                RotationConvention.VECTOR_OPERATOR));
91      }
92  
93  }