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.      */
  57.     public EclipticProvider(final IERSConventions conventions) {
  58.         this.conventions = conventions;
  59.         this.obliquity   = conventions.getMeanObliquityFunction();
  60.     }

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

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

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

  84.     /** Internal class used only for serialization. */
  85.     private static class DataTransferObject implements Serializable {

  86.         /** Serializable UID. */
  87.         private static final long serialVersionUID = 20140516L;

  88.         /** IERS conventions. */
  89.         private final IERSConventions conventions;

  90.         /** Simple constructor.
  91.          * @param conventions IERS conventions
  92.          */
  93.         DataTransferObject(final IERSConventions conventions) {
  94.             this.conventions = conventions;
  95.         }

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

  107.     }

  108. }