EclipticProvider.java

  1. /* Contributed in the public domain.
  2.  * Licensed to CS Systèmes d'Information (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.RealFieldElement;
  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.errors.OrekitException;
  26. import org.orekit.errors.OrekitInternalError;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.time.TimeScalarFunction;
  30. import org.orekit.utils.IERSConventions;

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

  47.     /** Serializable UID. */
  48.     private static final long serialVersionUID = 20140516L;

  49.     /** IERS conventions. */
  50.     private final IERSConventions conventions;

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

  53.     /**
  54.      * Create a transform provider from MOD to an ecliptically aligned frame.
  55.      * @param conventions IERS conventions
  56.      * @throws OrekitException if the mean obliquity of the ecliptic function can not be
  57.      *                         loaded.
  58.      */
  59.     public EclipticProvider(final IERSConventions conventions) throws OrekitException {
  60.         this.conventions = conventions;
  61.         this.obliquity   = conventions.getMeanObliquityFunction();
  62.     }

  63.     @Override
  64.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {
  65.         //mean obliquity of date
  66.         final double epsA = obliquity.value(date);
  67.         return new Transform(date, new Rotation(Vector3D.MINUS_I, epsA, RotationConvention.VECTOR_OPERATOR));
  68.     }

  69.     @Override
  70.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date)
  71.         throws OrekitException {
  72.         //mean obliquity of date
  73.         final T epsA = obliquity.value(date);
  74.         return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getMinusI(date.getField()),
  75.                                                               epsA,
  76.                                                               RotationConvention.VECTOR_OPERATOR));
  77.     }

  78.     /** Replace the instance with a data transfer object for serialization.
  79.      * <p>
  80.      * This intermediate class serializes only the frame key.
  81.      * </p>
  82.      * @return data transfer object that will be serialized
  83.      */
  84.     private Object writeReplace() {
  85.         return new DataTransferObject(conventions);
  86.     }

  87.     /** Internal class used only for serialization. */
  88.     private static class DataTransferObject implements Serializable {

  89.         /** Serializable UID. */
  90.         private static final long serialVersionUID = 20140516L;

  91.         /** IERS conventions. */
  92.         private final IERSConventions conventions;

  93.         /** Simple constructor.
  94.          * @param conventions IERS conventions
  95.          */
  96.         DataTransferObject(final IERSConventions conventions) {
  97.             this.conventions = conventions;
  98.         }

  99.         /** Replace the deserialized data transfer object with a {@link EclipticProvider}.
  100.          * @return replacement {@link EclipticProvider}
  101.          */
  102.         private Object readResolve() {
  103.             try {
  104.                 // retrieve a transform
  105.                 return new EclipticProvider(conventions);
  106.             } catch (OrekitException oe) {
  107.                 throw new OrekitInternalError(oe);
  108.             }
  109.         }

  110.     }

  111. }