TDB top-level property
Barycentric Dynamical Time (TDB): TDB varies from TDT by periodic variations
Implementation
// ignore: non_constant_identifier_names
final TimeInstantUnits TDB = TimeInstantUnits(
'Barycentric Dynamical Time',
'TDB',
'TDB',
'Barycentric Dynamical Time',
1.0,
false,
-32.184, (dynamic val) {
// TDB = TAI + 32.184 + 0.001658sin(g) + 0.000014sin(2g)...
// where g = 357.53 deg + 0.9856003(JD - 2451545.0) deg... (Julian dates are in the TAI time scale)
final d = val is num
? val.toDouble()
: val is Number
? val.toDouble()
: 0.0;
final gRad = (357.53 + 0.9856003 * ((d / 86400.0) - 15341.0)) * (pi / 180.0);
return Double(d + 32.184 + 0.001658 * sin(gRad) + 0.000014 * sin(2.0 * gRad));
}, (dynamic val) {
// TAI = TDB - 32.184 - 0.001658sin(g) - 0.000014sin(2g)...
// where g = 357.53 deg + 0.9856003(JD - 2451545.0) deg... (Julian dates are in the TAI time scale)
final d = val is num
? val.toDouble()
: val is Number
? val.toDouble()
: 0.0;
// Too convoluted to solve analytically (because g is a function of
// the Julian Date in the TAI scale... instead, get close and then search).
var taiTest = d;
var step = 10.0;
const epsilon = 1.0e-8;
const maxCount = 10000;
var count = 0;
var tdbTest = TDB.fromMks(d).toDouble();
var delta = tdbTest - taiTest;
var prevDelta = double.maxFinite;
while ((delta.abs() > epsilon) && (count < maxCount)) {
// See if we got farther away (if so reverse and take smaller steps)
if (delta.abs() > prevDelta.abs()) step *= -0.5;
// Step
taiTest += step;
prevDelta = delta;
count++;
// value & delta
tdbTest = TDB.fromMks(taiTest).toDouble();
delta = tdbTest - d;
}
// taiTest now returns a tcb value within epsilon (or loop count ran out)
return Double(taiTest);
});