GMSTScale.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (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.CalculusFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.utils.Constants;

  21. /** Greenwich Mean Sidereal Time.
  22.  * <p>The Greenwich Mean Sidereal Time is the hour angle between the meridian of Greenwich
  23.  * and mean equinox of date at 0h UT1.</p>
  24.  * <p>This is intended to be accessed thanks to {@link TimeScales},
  25.  * so there is no public constructor.</p>
  26.  * @author Luc Maisonobe
  27.  * @see AbsoluteDate
  28.  * @since 5.1
  29.  */
  30. public class GMSTScale implements TimeScale {

  31.     /** Duration of one julian day. */
  32.     private static final long FULL_DAY = 86400L;

  33.     /** Duration of an half julian day. */
  34.     private static final long HALF_DAY = FULL_DAY / 2;

  35.     /** Coefficient for degree 0. */
  36.     private static final double C0 = 24110.54841;

  37.     /** Coefficient for degree 1. */
  38.     private static final double C1 = 8640184.812866;

  39.     /** Coefficient for degree 2. */
  40.     private static final double C2 = 0.093104;

  41.     /** Coefficient for degree 3. */
  42.     private static final double C3 = -0.0000062;

  43.     /** Universal Time 1 time scale. */
  44.     private final UT1Scale     ut1;

  45.     /** Reference date for GMST. */
  46.     private final AbsoluteDate referenceDate;

  47.     // GST 1982: 24110.54841 + 8640184.812866 t + 0.093104 t2 - 6.2e-6 t3
  48.     // GST 2000: 24110.5493771 + 8639877.3173760 tu + 307.4771600 te + 0.0931118 te2 - 0.0000062 te3 + 0.0000013 te4

  49.     /** Package private constructor for the factory.
  50.      * @param ut1 Universal Time 1 scale
  51.      */
  52.     GMSTScale(final UT1Scale ut1) {
  53.         this.ut1           = ut1;
  54.         this.referenceDate = new AbsoluteDate(2000, 1, 1, 12, 0, 0.0, ut1);
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public TimeOffset offsetFromTAI(final AbsoluteDate date) {

  59.         // julian seconds since reference date
  60.         final double ts = date.durationFrom(referenceDate);

  61.         // julian centuries since reference date
  62.         final double tc = ts / Constants.JULIAN_CENTURY;

  63.         // GMST at 0h00 UT1 in seconds = offset with respect to UT1
  64.         final double gmst0h = C0 + tc * (C1 + tc * (C2 + tc * C3));

  65.         // offset with respect to TAI
  66.         final TimeOffset offset = new TimeOffset(gmst0h).add(ut1.offsetFromTAI(date));

  67.         // normalize offset between -43200 and +43200 seconds
  68.         long clipped = offset.getSeconds() < 0L ?
  69.                        (offset.getSeconds() - HALF_DAY) % FULL_DAY + HALF_DAY :
  70.                        (offset.getSeconds() + HALF_DAY) % FULL_DAY - HALF_DAY;
  71.         if (clipped == HALF_DAY && offset.getAttoSeconds() > 0L) {
  72.             clipped -= FULL_DAY;
  73.         }
  74.         return new TimeOffset(clipped, offset.getAttoSeconds());

  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public <T extends CalculusFieldElement<T>> T offsetFromTAI(final FieldAbsoluteDate<T> date) {

  79.         // julian seconds since reference date
  80.         final T ts = date.durationFrom(referenceDate);

  81.         // julian centuries since reference date
  82.         final T tc = ts.divide(Constants.JULIAN_CENTURY);

  83.         // GMST at 0h00 UT1 in seconds = offset with respect to UT1
  84.         final T gmst0h = tc.multiply(C3).add(C2).multiply(tc).add(C1).multiply(tc).add(C0);

  85.         // offset with respect to TAI
  86.         final T offset = gmst0h.add(ut1.offsetFromTAI(date));

  87.         // normalize offset between -43200 and +43200 seconds
  88.         return offset.subtract(FULL_DAY * FastMath.floor((offset.getReal() + HALF_DAY) / FULL_DAY));

  89.     }

  90.     /** {@inheritDoc} */
  91.     public String getName() {
  92.         return "GMST";
  93.     }

  94.     /** {@inheritDoc} */
  95.     public String toString() {
  96.         return getName();
  97.     }

  98. }