1 /* Copyright 2002-2024 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
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.util.FastMath;
21 import org.hipparchus.util.FieldSinCos;
22 import org.hipparchus.util.SinCos;
23 import org.orekit.utils.Constants;
24
25 /** Barycentric Dynamic Time.
26 * <p>Time used to take account of time dilation when calculating orbits of planets,
27 * asteroids, comets and interplanetary spacecraft in the Solar system. It was based
28 * on a Dynamical time scale but was not well defined and not rigorously correct as
29 * a relativistic time scale. It was subsequently deprecated in favour of
30 * Barycentric Coordinate Time (TCB), but at the 2006 General Assembly of the
31 * International Astronomical Union TDB was rehabilitated by making it a specific
32 * fixed linear transformation of TCB.</p>
33 * <p>By convention, TDB = TT + 0.001658 sin(g) + 0.000014 sin(2g)seconds
34 * where g = 357.53 + 0.9856003 (JD - 2451545) degrees.</p>
35 * @author Aude Privat
36 */
37 public class TDBScale implements TimeScale {
38
39 /** Serializable UID. */
40 private static final long serialVersionUID = 20240720L;
41
42 /** Constant term for g angle. */
43 private static final double G0 = FastMath.toRadians(357.53);
44
45 /** Slope term for g angle. */
46 private static final double G1 = FastMath.toRadians(0.9856003);
47
48 /** Factor for sin(g). */
49 private static final double SIN_G_FACTOR = 0.001658;
50
51 /** Factor for sin(2g). */
52 private static final double TWO_SIN_2G_FACTOR = 2 * 0.000014;
53
54 /** TT time scale. */
55 private final TimeScale tt;
56
57 /** Reference Epoch. */
58 private final AbsoluteDate j2000Epoch;
59
60 /**
61 * Package private constructor for the factory.
62 *
63 * @param tt TT time scale.
64 * @param j2000Epoch reference date for this time scale.
65 */
66 TDBScale(final TimeScale tt, final AbsoluteDate j2000Epoch) {
67 this.tt = tt;
68 this.j2000Epoch = j2000Epoch;
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 public TimeOffset offsetFromTAI(final AbsoluteDate date) {
74 final double dtDays = date.durationFrom(j2000Epoch) / Constants.JULIAN_DAY;
75 final SinCos sc = FastMath.sinCos(G0 + G1 * dtDays);
76 return tt.offsetFromTAI(date).
77 add(new TimeOffset(sc.sin() * (SIN_G_FACTOR + TWO_SIN_2G_FACTOR * sc.cos())));
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public <T extends CalculusFieldElement<T>> T offsetFromTAI(final FieldAbsoluteDate<T> date) {
83 final T dtDays = date.durationFrom(j2000Epoch).divide(Constants.JULIAN_DAY);
84 final FieldSinCos<T> sc = FastMath.sinCos(dtDays.multiply(G1).add(G0));
85 return tt.offsetFromTAI(date).
86 add(sc.sin().multiply(sc.cos().multiply(TWO_SIN_2G_FACTOR).add(SIN_G_FACTOR)));
87 }
88
89 /** {@inheritDoc} */
90 public String getName() {
91 return "TDB";
92 }
93
94 /** {@inheritDoc} */
95 public String toString() {
96 return getName();
97 }
98
99 }