Take the orbits at TDB as the spins already were, so a locked moon faces the planet it is drawn round

Every element set here runs on TDB: Standish's T_eph, the SSD satellite and SBDB epochs, the
IAU's d and T. bodyOrientation already took the clock's UTC to TDB, but SystemOrbitsRenderer.update
and the body page's heliocentricPosition fed the UTC date straight to meanElementsAt, so in one
frame each body's place was 69.184 s behind its spin. That is n x 69 s of orbit: Phobos 0.90
degrees, Mimas 0.31, Deimos 0.23, Enceladus 0.21, Miranda 0.20, Io 0.16, Tethys 0.15, Europa
0.08, the Moon 0.011. 48319c3's table measured the app at a UTC date against Horizons at the same
number read as TDB, which hid it, and its "nothing for anything else" was wrong: Io's 0.16 is four
to five times Io's worst model error there (0.035).

tdbFromUtc, in constants.ts, is now the one conversion, and positions and spins both go through
it. In the running app, clock pinned to 2025-06-01 12:00 UTC, Io's face towards Jupiter is at
0.024 E, latitude -0.009, where Horizons (observer quantity 14 from Jupiter's centre) has 0.036 E
and -0.003: 0.012 degrees apart, where it was 0.175. The renderer spec checks that point, and now
hands its frozen Horizons vectors, which are TDB, to update() as the UTC dates that name them,
69.184 s earlier; the same frozen rows fed at the UTC date fail for Io and Europa. A body-page test
checks that the Sun lights the point it stands over at the same TDB instant the body is turned for.

Controls: taking the renderer's orbits at the clock's UTC fails "faces jupiter and the Sun with the
points Horizons gives on io"; taking the page's Sun there fails "takes the Sun where it stands at
the same TDB instant".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-29 18:45:26 +02:00
co-authored by Claude Opus 5.5
parent f8ee3ac3ab
commit d4808788ec
5 changed files with 56 additions and 20 deletions
+11
View File
@@ -27,6 +27,17 @@ export const GM_SUN_AU3_PER_DAY2 = 0.01720209895 * 0.01720209895;
*/
export const TT_MINUS_UTC_DAYS = 69.184 / 86400;
/**
* The TDB date every element set here is evaluated at, for a date on the map's clock, which is
* UTC: Standish's T_eph, the SSD satellite and SBDB epochs and the IAU's d and T all run on TDB.
* Positions and spins both go through this, so a locked moon's face and the orbit it is drawn on
* are taken at the same instant; taken at the clock's date, the orbits ran 69 s behind the spins,
* which is 0.9 degrees of Phobos's orbit and 0.16 of Io's.
*/
export function tdbFromUtc(jdUtc: number): number {
return jdUtc + TT_MINUS_UTC_DAYS;
}
/** Converts a JS `Date` into a Julian date (days), for driving the Kepler propagator "now". */
export function dateToJulianDate(date: Date = new Date()): number {
return date.getTime() / 86400000 + 2440587.5;
@@ -1,8 +1,11 @@
import * as THREE from 'three/webgpu';
import { describe, expect, it } from 'vitest';
import { TT_MINUS_UTC_DAYS } from '../astro/constants';
import { eclipticToEquatorial } from '../astro/coordinates';
import { meanElementsAt, positionAtEpoch } from '../astro/kepler';
import { BodyRecord } from '../models/body.model';
import { bodyPageView } from './body-orientation';
import { bodyOrientation, bodyPageView } from './body-orientation';
// Earth (the Earth-Moon barycentre's mean elements) and the Moon as bodies.json carries them.
const EARTH: BodyRecord = {
@@ -51,6 +54,17 @@ describe('bodyPageView', () => {
expect(Math.abs(moon.latDeg - 1.503004)).toBeLessThan(0.05);
});
it('takes the Sun where it stands at the same TDB instant the body is turned for', () => {
// Earth's own sphere, turned as the system view turns it, and the Sun seen from Earth's mean
// place at the clock's date taken to TDB: the page must light that same point of its map.
const planet = new THREE.Quaternion();
const sun = new THREE.Vector3();
bodyPageView(EARTH, BODIES, JUNE_1_2025_NOON_UTC, SUN_AZIMUTH, planet, sun);
const place = eclipticToEquatorial(positionAtEpoch(meanElementsAt(EARTH.orbit, EARTH.rates, JUNE_1_2025_NOON_UTC + TT_MINUS_UTC_DAYS)));
const expected = new THREE.Vector3(-place.x, -place.y, -place.z).normalize().applyQuaternion(bodyOrientation(EARTH.rotationalElements!, JUNE_1_2025_NOON_UTC).invert());
expect(sun.clone().applyQuaternion(planet.clone().invert()).angleTo(expected)).toBeLessThan(1e-9);
});
it('keeps the pole up and the Sun where the page’s light stands, turning the body under it', () => {
const planet = new THREE.Quaternion();
const sun = new THREE.Vector3();
+7 -6
View File
@@ -1,6 +1,6 @@
import * as THREE from 'three/webgpu';
import { TT_MINUS_UTC_DAYS } from '../astro/constants';
import { tdbFromUtc } from '../astro/constants';
import { CartesianCoordinates, eclipticToEquatorial, laplacePlaneToEquatorial } from '../astro/coordinates';
import { meanElementsAt, positionAtEpoch } from '../astro/kepler';
import { orientationAt } from '../astro/rotational-elements';
@@ -51,10 +51,10 @@ export function poleFrame(pole: { raDeg: number; decDeg: number }, target = new
* and on to where the pole points.
*
* The clock is UTC and the IAU's elements run on TDB, 69.184 s ahead; in that time Earth turns
* 0.29 degrees, Jupiter 0.70 and Phobos 0.90, so the difference is added here.
* 0.29 degrees, Jupiter 0.70 and Phobos 0.90, so the date is taken to TDB here (see `tdbFromUtc`).
*/
export function bodyOrientation(elements: RotationalElements, jdUtc: number, target = new THREE.Quaternion()): THREE.Quaternion {
const { poleRaDeg, poleDecDeg, primeMeridianDeg } = orientationAt(elements, jdUtc + TT_MINUS_UTC_DAYS);
const { poleRaDeg, poleDecDeg, primeMeridianDeg } = orientationAt(elements, tdbFromUtc(jdUtc));
return poleFrame({ raDeg: poleRaDeg, decDeg: poleDecDeg }, target)
.multiply(scratchTurn.setFromAxisAngle(Z_AXIS, primeMeridianDeg * DEG_TO_RAD))
.multiply(MAP_TO_BODY);
@@ -62,13 +62,14 @@ export function bodyOrientation(elements: RotationalElements, jdUtc: number, tar
/** Where a body is from the Sun at a date, in the ICRF, AU: a moon's planet's place plus its own. */
function heliocentricPosition(body: BodyRecord, bodies: readonly BodyRecord[], jdUtc: number): CartesianCoordinates {
const own = positionAtEpoch(meanElementsAt(body.orbit, body.rates, jdUtc));
const jdTdb = tdbFromUtc(jdUtc);
const own = positionAtEpoch(meanElementsAt(body.orbit, body.rates, jdTdb));
const parent = body.parentBodyId ? bodies.find((candidate) => candidate.id === body.parentBodyId) : undefined;
if (!parent) {
return eclipticToEquatorial(own);
}
const offset = body.laplacePole ? laplacePlaneToEquatorial(own, body.laplacePole) : eclipticToEquatorial(own);
const centre = eclipticToEquatorial(positionAtEpoch(meanElementsAt(parent.orbit, parent.rates, jdUtc)));
const centre = eclipticToEquatorial(positionAtEpoch(meanElementsAt(parent.orbit, parent.rates, jdTdb)));
return { x: centre.x + offset.x, y: centre.y + offset.y, z: centre.z + offset.z };
}
@@ -92,7 +93,7 @@ export function bodyPageView(body: BodyRecord, bodies: readonly BodyRecord[], jd
if (!elements) {
return false;
}
const { poleRaDeg, poleDecDeg } = orientationAt(elements, jdUtc + TT_MINUS_UTC_DAYS);
const { poleRaDeg, poleDecDeg } = orientationAt(elements, tdbFromUtc(jdUtc));
// From the ICRF into the body's frame with its pole on +Y, before the turn about that pole.
const toPage = poleFrame({ raDeg: poleRaDeg, decDeg: poleDecDeg }, scratchPage).multiply(MAP_TO_BODY).invert();
const position = heliocentricPosition(body, bodies, jdUtc);