EclipticProvider.java

  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. import java.io.Serializable;

  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.errors.OrekitException;
  28. import org.orekit.errors.OrekitInternalError;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.time.TimeScalarFunction;
  32. import org.orekit.time.TimeScales;
  33. import org.orekit.utils.IERSConventions;

  34. /**
  35.  * An inertial frame aligned with the ecliptic.
  36.  * <p>
  37.  * The IAU defines the ecliptic as "the plane perpendicular to the mean heliocentric
  38.  * orbital angular momentum vector of the Earth-Moon barycentre in the BCRS (IAU 2006
  39.  * Resolution B1)." The +z axis is aligned with the angular momentum vector, and the +x
  40.  * axis is aligned with +x axis of {@link Frames#getMOD(IERSConventions) MOD}.
  41.  * </p>
  42.  *
  43.  * <p>
  44.  * This implementation agrees with the JPL 406 ephemerides to within 0.5 arc seconds.
  45.  * </p>
  46.  *
  47.  * @since 7.0
  48.  */
  49. public class EclipticProvider implements TransformProvider {

  50.     /** Serializable UID. */
  51.     private static final long serialVersionUID = 20140516L;

  52.     /** IERS conventions. */
  53.     private final IERSConventions conventions;

  54.     /** the obliquity of the ecliptic, in radians as a function of time. */
  55.     private final transient TimeScalarFunction obliquity;

  56.     /**
  57.      * Create a transform provider from MOD to an ecliptically aligned frame.
  58.      *
  59.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  60.      *
  61.      * @param conventions IERS conventions
  62.      * @see #EclipticProvider(IERSConventions, TimeScales)
  63.      */
  64.     @DefaultDataContext
  65.     public EclipticProvider(final IERSConventions conventions) {
  66.         this(conventions, DataContext.getDefault().getTimeScales());
  67.     }

  68.     /**
  69.      * Create a transform provider from MOD to an ecliptically aligned frame.
  70.      * @param conventions IERS conventions
  71.      * @param timeScales to use in computing the transformation.
  72.      * @since 10.1
  73.      */
  74.     public EclipticProvider(final IERSConventions conventions,
  75.                             final TimeScales timeScales) {
  76.         this.conventions = conventions;
  77.         this.obliquity   = conventions.getMeanObliquityFunction(timeScales);
  78.     }

  79.     @Override
  80.     public Transform getTransform(final AbsoluteDate date) {
  81.         //mean obliquity of date
  82.         final double epsA = obliquity.value(date);
  83.         return new Transform(date, new Rotation(Vector3D.MINUS_I, epsA, RotationConvention.VECTOR_OPERATOR));
  84.     }

  85.     @Override
  86.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  87.         //mean obliquity of date
  88.         final T epsA = obliquity.value(date);
  89.         return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getMinusI(date.getField()),
  90.                                                               epsA,
  91.                                                               RotationConvention.VECTOR_OPERATOR));
  92.     }

  93.     /** Replace the instance with a data transfer object for serialization.
  94.      * <p>
  95.      * This intermediate class serializes only the frame key.
  96.      * </p>
  97.      * @return data transfer object that will be serialized
  98.      */
  99.     @DefaultDataContext
  100.     private Object writeReplace() {
  101.         return new DataTransferObject(conventions);
  102.     }

  103.     /** Internal class used only for serialization. */
  104.     @DefaultDataContext
  105.     private static class DataTransferObject implements Serializable {

  106.         /** Serializable UID. */
  107.         private static final long serialVersionUID = 20140516L;

  108.         /** IERS conventions. */
  109.         private final IERSConventions conventions;

  110.         /** Simple constructor.
  111.          * @param conventions IERS conventions
  112.          */
  113.         DataTransferObject(final IERSConventions conventions) {
  114.             this.conventions = conventions;
  115.         }

  116.         /** Replace the deserialized data transfer object with a {@link EclipticProvider}.
  117.          * @return replacement {@link EclipticProvider}
  118.          */
  119.         private Object readResolve() {
  120.             try {
  121.                 // retrieve a transform
  122.                 return new EclipticProvider(conventions);
  123.             } catch (OrekitException oe) {
  124.                 throw new OrekitInternalError(oe);
  125.             }
  126.         }

  127.     }

  128. }