MODProvider.java

  1. /* Copyright 2002-2013 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.Vector3D;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.TimeFunction;
  24. import org.orekit.utils.IERSConventions;

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

  32.     /** Serializable UID. */
  33.     private static final long serialVersionUID = 20130920L;

  34.     /** Conventions. */
  35.     private final IERSConventions conventions;

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

  38.     /** Constant rotation betwee ecliptic and equatoror poles at J2000.0. */
  39.     private final Rotation r4;

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

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

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

  60.         // elementary rotations for precession
  61.         final Rotation r1 = new Rotation(Vector3D.PLUS_K, -angles[2]);
  62.         final Rotation r2 = new Rotation(Vector3D.PLUS_I,  angles[1]);
  63.         final Rotation r3 = new Rotation(Vector3D.PLUS_K,  angles[0]);

  64.         // complete precession
  65.         final Rotation precession = r1.applyTo(r2.applyTo(r3.applyTo(r4)));

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

  68.     }

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

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

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

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

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

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

  101.     }

  102. }