TDBScale.java

  1. /* Copyright 2002-2018 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.time;

  18. import org.hipparchus.RealFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.utils.Constants;

  21. /** Barycentric Dynamic Time.
  22.  * <p>Time used to take account of time dilation when calculating orbits of planets,
  23.  * asteroids, comets and interplanetary spacecraft in the Solar system. It was based
  24.  * on a Dynamical time scale but was not well defined and not rigorously correct as
  25.  * a relativistic time scale. It was subsequently deprecated in favour of
  26.  * Barycentric Coordinate Time (TCB), but at the 2006 General Assembly of the
  27.  * International Astronomical Union TDB was rehabilitated by making it a specific
  28.  * fixed linear transformation of TCB.</p>
  29.  * <p>By convention, TDB = TT + 0.001658 sin(g) + 0.000014 sin(2g)seconds
  30.  * where g = 357.53 + 0.9856003 (JD - 2451545) degrees.</p>
  31.  * @author Aude Privat
  32.  */
  33. public class TDBScale implements TimeScale {

  34.     /** Serializable UID. */
  35.     private static final long serialVersionUID = 20131209L;

  36.     /** Constant term for g angle. */
  37.     private static final double G0 = 357.53;

  38.     /** Slope term for g angle. */
  39.     private static final double G1 = 0.9856003;

  40.     /** Factor for sin(g). */
  41.     private static final double SIN_G_FACTOR = 0.001658;

  42.     /** Factor for sin(2g). */
  43.     private static final double SIN_2G_FACTOR = 0.000014;

  44.     /** Package private constructor for the factory.
  45.      */
  46.     TDBScale() {
  47.     }

  48.     /** {@inheritDoc} */
  49.     @Override
  50.     public double offsetFromTAI(final AbsoluteDate date) {
  51.         final double dtDays = date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY;
  52.         final double g = FastMath.toRadians(G0 + G1 * dtDays);
  53.         return TimeScalesFactory.getTT().offsetFromTAI(date) + (SIN_G_FACTOR * FastMath.sin(g) + SIN_2G_FACTOR * FastMath.sin(2 * g));
  54.     }

  55.     /** {@inheritDoc} */
  56.     @Override
  57.     public <T extends RealFieldElement<T>> T offsetFromTAI(final FieldAbsoluteDate<T> date) {
  58.         final T dtDays = date.durationFrom(AbsoluteDate.J2000_EPOCH).divide(Constants.JULIAN_DAY);
  59.         final T g = dtDays.multiply(G1).add(G0).multiply(FastMath.PI / 180);
  60.         return TimeScalesFactory.getTT().offsetFromTAI(date).
  61.                         add(g.sin().multiply(SIN_G_FACTOR).add(g.multiply(2).sin().multiply(SIN_2G_FACTOR)));
  62.     }

  63.     /** {@inheritDoc} */
  64.     public String getName() {
  65.         return "TDB";
  66.     }

  67.     /** {@inheritDoc} */
  68.     public String toString() {
  69.         return getName();
  70.     }

  71. }