MODProvider.java

  1. /* Copyright 2002-2016 CS Systèmes d'Information
  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.apache.commons.math3.geometry.euclidean.threed.Rotation;
  20. import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
  21. import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;
  22. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitInternalError;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.TimeFunction;
  27. import org.orekit.utils.IERSConventions;

  28. /** Mean Equator, Mean Equinox Frame.
  29.  * <p>This frame handles precession effects according to to selected IERS conventions.</p>
  30.  * <p>Its parent frame is the GCRF frame.<p>
  31.  * <p>It is sometimes called Mean of Date (MoD) frame.<p>
  32.  * @author Pascal Parraud
  33.  */
  34. class MODProvider implements TransformProvider {

  35.     /** Serializable UID. */
  36.     private static final long serialVersionUID = 20130920L;

  37.     /** Conventions. */
  38.     private final IERSConventions conventions;

  39.     /** Function computing the precession angles. */
  40.     private final transient TimeFunction<double[]> precessionFunction;

  41.     /** Constant rotation between ecliptic and equator poles at J2000.0. */
  42.     private final Rotation r4;

  43.     /** Simple constructor.
  44.      * @param conventions IERS conventions to apply
  45.      * @exception OrekitException if IERS conventions tables cannot be read
  46.      */
  47.     MODProvider(final IERSConventions conventions) throws OrekitException {
  48.         this.conventions        = conventions;
  49.         this.precessionFunction = conventions.getPrecessionFunction();
  50.         final TimeFunction<Double> epsilonAFunction = conventions.getMeanObliquityFunction();
  51.         final AbsoluteDate date0 = conventions.getNutationReferenceEpoch();
  52.         final double epsilon0 = epsilonAFunction.value(date0);
  53.         r4 = new Rotation(Vector3D.PLUS_I, epsilon0, RotationConvention.FRAME_TRANSFORM);
  54.     }

  55.     /** Get the transform from parent frame.
  56.      * <p>The update considers the precession effects.</p>
  57.      * @param date new value of the date
  58.      * @return transform at the specified date
  59.      */
  60.     public Transform getTransform(final AbsoluteDate date) {

  61.         // compute the precession angles phiA, omegaA, chiA
  62.         final double[] angles = precessionFunction.value(date);

  63.         // complete precession
  64.         final Rotation precession = r4.compose(new Rotation(RotationOrder.ZXZ, RotationConvention.FRAME_TRANSFORM,
  65.                                                             -angles[0], -angles[1], angles[2]),
  66.                                                RotationConvention.FRAME_TRANSFORM);

  67.         // set up the transform from parent GCRF
  68.         return new Transform(date, precession);

  69.     }

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

  79.     /** Internal class used only for serialization. */
  80.     private static class DataTransferObject implements Serializable {

  81.         /** Serializable UID. */
  82.         private static final long serialVersionUID = 20131209L;

  83.         /** Conventions. */
  84.         private final IERSConventions conventions;

  85.         /** Simple constructor.
  86.          * @param conventions IERSConventions conventions
  87.          */
  88.         DataTransferObject(final IERSConventions conventions) {
  89.             this.conventions = conventions;
  90.         }

  91.         /** Replace the deserialized data transfer object with a {@link MODProvider}.
  92.          * @return replacement {@link MODProvider}
  93.          */
  94.         private Object readResolve() {
  95.             try {
  96.                 // retrieve a managed frame
  97.                 return new MODProvider(conventions);
  98.             } catch (OrekitException oe) {
  99.                 throw new OrekitInternalError(oe);
  100.             }
  101.         }

  102.     }

  103. }