Spaces:
Running

AK51 commited on
Commit
ed0e4ea
·
verified ·
1 Parent(s): 7b6b412

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.js +145 -12
  2. grail_gravity.js +196 -0
  3. index.html +62 -11
app.js CHANGED
@@ -1,6 +1,7 @@
1
  import * as THREE from "three";
2
  import { OrbitControls } from "three/addons/controls/OrbitControls.js";
3
  import { LOCATIONS } from "./locations.js";
 
4
 
5
  /* =========================================================
6
  Moon textures. Each style has a small 2K map (instant view)
@@ -1133,6 +1134,7 @@ function wireToggles() {
1133
  }
1134
  if ("pearth" in btn.dataset) setPerturbation("earth", btn.dataset.pearth === "on");
1135
  if ("psun" in btn.dataset) setPerturbation("sun", btn.dataset.psun === "on");
 
1136
  });
1137
  });
1138
  });
@@ -1157,11 +1159,16 @@ function setPerturbation(body, on) {
1157
  function updatePerturbReadout() {
1158
  const el = document.getElementById("pert-readout");
1159
  if (!el) return;
 
 
 
 
1160
  const on = [];
 
1161
  if (pert.earth) on.push("Earth");
1162
  if (pert.sun) on.push("Sun");
1163
  el.textContent = on.length
1164
- ? `Perturbed by ${on.join(" + ")} gravity — orbit evolves over time`
1165
  : "Two-body orbit (ideal Kepler ellipse)";
1166
  }
1167
 
@@ -1232,7 +1239,99 @@ const orbit = { a: 3000, e: 0.1, i: 45, raan: 0, argp: 0, nu: 0, speed: 100 };
1232
  precesses and deforms over time, exactly as a real one would. */
1233
  const MU_EARTH = 398600.4418; // km^3/s^2
1234
  const MU_SUN = 1.32712440018e11; // km^3/s^2
1235
- const pert = { earth: false, sun: false };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1236
 
1237
  // Integrated state in a Moon-centered frame, kilometres and km/s. The
1238
  // axes match the render frame used by computeSatPosition (+Y = Moon pole,
@@ -1241,7 +1340,7 @@ const satState = { pos: new THREE.Vector3(), vel: new THREE.Vector3(), active: f
1241
  let perturbTrail = []; // recent positions (world units) for the evolving path
1242
  const TRAIL_MAX = 1400;
1243
 
1244
- function perturbationsOn() { return pert.earth || pert.sun; }
1245
 
1246
  /* Seed the integrator's position+velocity from the current Keplerian
1247
  elements, so turning perturbations on continues smoothly from the
@@ -1281,19 +1380,42 @@ function stateFromElements() {
1281
  function reseedSatState() {
1282
  const s = stateFromElements();
1283
  satState.pos.copy(s.pos);
1284
- satState.vel.copy(s.vel);
 
 
 
 
 
 
 
1285
  satState.active = perturbationsOn();
 
1286
  perturbTrail = [];
 
1287
  }
1288
 
1289
- /* Gravitational acceleration (km/s²) at a Moon-centered position (km). */
 
1290
  const _acc = new THREE.Vector3();
1291
  const _sb = new THREE.Vector3();
1292
  const _rel = new THREE.Vector3();
1293
- function orbitAcceleration(posKm) {
1294
- // Moon central term.
 
1295
  const r = posKm.length();
1296
  _acc.copy(posKm).multiplyScalar(-MU_MOON / (r * r * r));
 
 
 
 
 
 
 
 
 
 
 
 
1297
  // Third bodies: direct (on satellite) minus indirect (on the Moon).
1298
  const addBody = (dirUnit, distKm, mu) => {
1299
  _sb.copy(dirUnit).multiplyScalar(distKm); // body position (km)
@@ -1316,7 +1438,7 @@ const _k1a = new THREE.Vector3(), _k2a = new THREE.Vector3();
1316
  const _k3a = new THREE.Vector3(), _k4a = new THREE.Vector3();
1317
  const _tmp = new THREE.Vector3();
1318
  function integrateSatState(seconds) {
1319
- if (seconds <= 0) return;
1320
  // Keep each RK4 step under ~1/400 of the orbital period for accuracy.
1321
  const period = 2 * Math.PI * Math.sqrt((orbit.a ** 3) / MU_MOON);
1322
  const maxStep = period / 400;
@@ -1325,20 +1447,28 @@ function integrateSatState(seconds) {
1325
  for (let step = 0; step < nSteps; step++) {
1326
  const p = satState.pos, v = satState.vel;
1327
  _k1v.copy(v);
1328
- _k1a.copy(orbitAcceleration(p));
1329
  _tmp.copy(p).addScaledVector(_k1v, dt / 2);
1330
  _k2v.copy(v).addScaledVector(_k1a, dt / 2);
1331
- _k2a.copy(orbitAcceleration(_tmp));
1332
  _tmp.copy(p).addScaledVector(_k2v, dt / 2);
1333
  _k3v.copy(v).addScaledVector(_k2a, dt / 2);
1334
- _k3a.copy(orbitAcceleration(_tmp));
1335
  _tmp.copy(p).addScaledVector(_k3v, dt);
1336
  _k4v.copy(v).addScaledVector(_k3a, dt);
1337
- _k4a.copy(orbitAcceleration(_tmp));
1338
  p.addScaledVector(_k1v, dt / 6).addScaledVector(_k2v, dt / 3)
1339
  .addScaledVector(_k3v, dt / 3).addScaledVector(_k4v, dt / 6);
1340
  v.addScaledVector(_k1a, dt / 6).addScaledVector(_k2a, dt / 3)
1341
  .addScaledVector(_k3a, dt / 3).addScaledVector(_k4a, dt / 6);
 
 
 
 
 
 
 
 
1342
  }
1343
  }
1344
 
@@ -1839,6 +1969,9 @@ function wireSatellite() {
1839
  bindNum("s-argp", "n-argp", (v) => { orbit.argp = v; elemChanged(); });
1840
  bindNum("s-nu", "n-nu", (v) => { orbit.nu = v; elemChanged(); });
1841
 
 
 
 
1842
  // L2 halo controls
1843
  bindNum("s-l2amp", "n-l2amp", (v) => { l2.amp = v; updateOrbitLine(); positionSatellite(); });
1844
  bindNum("s-l2phase", "n-l2phase", (v) => { l2.phase = v; positionSatellite(); });
 
1
  import * as THREE from "three";
2
  import { OrbitControls } from "three/addons/controls/OrbitControls.js";
3
  import { LOCATIONS } from "./locations.js";
4
+ import { GRAIL_REF_RADIUS_KM, GRAIL_MAX_DEGREE, GRAIL_COEFFS } from "./grail_gravity.js";
5
 
6
  /* =========================================================
7
  Moon textures. Each style has a small 2K map (instant view)
 
1134
  }
1135
  if ("pearth" in btn.dataset) setPerturbation("earth", btn.dataset.pearth === "on");
1136
  if ("psun" in btn.dataset) setPerturbation("sun", btn.dataset.psun === "on");
1137
+ if ("pmoon" in btn.dataset) setPerturbation("moonField", btn.dataset.pmoon === "on");
1138
  });
1139
  });
1140
  });
 
1159
  function updatePerturbReadout() {
1160
  const el = document.getElementById("pert-readout");
1161
  if (!el) return;
1162
+ if (satState.crashed && perturbationsOn()) {
1163
+ el.textContent = "💥 Orbit decayed — the satellite hit the surface. Change any element to re-launch.";
1164
+ return;
1165
+ }
1166
  const on = [];
1167
+ if (pert.moonField) on.push(`GRAIL map (deg ${gravDegree})`);
1168
  if (pert.earth) on.push("Earth");
1169
  if (pert.sun) on.push("Sun");
1170
  el.textContent = on.length
1171
+ ? `Perturbed by ${on.join(" + ")} — orbit evolves over time`
1172
  : "Two-body orbit (ideal Kepler ellipse)";
1173
  }
1174
 
 
1239
  precesses and deforms over time, exactly as a real one would. */
1240
  const MU_EARTH = 398600.4418; // km^3/s^2
1241
  const MU_SUN = 1.32712440018e11; // km^3/s^2
1242
+ const pert = { earth: false, sun: false, moonField: false };
1243
+
1244
+ /* =========================================================
1245
+ Moon gravity map — GRAIL GRGM1200A spherical harmonics.
1246
+ Instead of a point mass, the Moon's potential is
1247
+ U = (μ/r) Σ_n Σ_m (R/r)^n P̄_nm(sin φ) (C̄_nm cos mλ + S̄_nm sin mλ)
1248
+ with fully-normalized coefficients (C̄, S̄) from GRAIL, truncated to a
1249
+ user-selectable degree (2–18). The acceleration is evaluated with the
1250
+ Cunningham V/W recursion (Montenbruck & Gill, "Satellite Orbits",
1251
+ §3.2.4), which works directly in Cartesian Moon-fixed coordinates and
1252
+ has no singularity at the poles. Only n ≥ 2 is summed here; the n = 0
1253
+ term is the central point mass already in orbitAcceleration(), and the
1254
+ n = 1 terms vanish because the origin is the Moon's centre of mass.
1255
+ ========================================================= */
1256
+ const GRAV_NMAX = GRAIL_MAX_DEGREE;
1257
+ let gravDegree = GRAV_NMAX; // user-selectable truncation degree
1258
+ const gravC = [], gravS = []; // un-normalized coefficients
1259
+ (function buildGravityTables() {
1260
+ const fact = (k) => { let f = 1; for (let i = 2; i <= k; i++) f *= i; return f; };
1261
+ for (let n = 0; n <= GRAV_NMAX; n++) {
1262
+ gravC.push(new Float64Array(n + 1));
1263
+ gravS.push(new Float64Array(n + 1));
1264
+ }
1265
+ for (const [n, m, cBar, sBar] of GRAIL_COEFFS) {
1266
+ if (n > GRAV_NMAX) continue;
1267
+ // Un-normalize: C = C̄ · √((2−δ_m0)(2n+1)(n−m)!/(n+m)!)
1268
+ const N = Math.sqrt((m === 0 ? 1 : 2) * (2 * n + 1) * fact(n - m) / fact(n + m));
1269
+ gravC[n][m] = cBar * N;
1270
+ gravS[n][m] = sBar * N;
1271
+ }
1272
+ })();
1273
+ const _V = [], _W = [];
1274
+ for (let n = 0; n <= GRAV_NMAX + 1; n++) {
1275
+ _V.push(new Float64Array(GRAV_NMAX + 2));
1276
+ _W.push(new Float64Array(GRAV_NMAX + 2));
1277
+ }
1278
+
1279
+ /* Non-central acceleration (km/s²) from the GRAIL harmonics at a
1280
+ Moon-fixed position (xb toward 0°E, yb toward 90°E, zb north; km).
1281
+ Writes the result into `out` = [ax, ay, az]. */
1282
+ function harmonicAccelBody(xb, yb, zb, out) {
1283
+ const R = GRAIL_REF_RADIUS_KM;
1284
+ const nMax = gravDegree;
1285
+ const r2 = xb * xb + yb * yb + zb * zb;
1286
+ const rho = (R * R) / r2;
1287
+ const x0 = (R * xb) / r2, y0 = (R * yb) / r2, z0 = (R * zb) / r2;
1288
+ const V = _V, W = _W;
1289
+
1290
+ // Zonal terms V_n0 (W_n0 = 0).
1291
+ V[0][0] = R / Math.sqrt(r2); W[0][0] = 0;
1292
+ V[1][0] = z0 * V[0][0]; W[1][0] = 0;
1293
+ for (let n = 2; n <= nMax + 1; n++) {
1294
+ V[n][0] = ((2 * n - 1) * z0 * V[n - 1][0] - (n - 1) * rho * V[n - 2][0]) / n;
1295
+ W[n][0] = 0;
1296
+ }
1297
+ // Tesseral / sectoral terms.
1298
+ for (let m = 1; m <= nMax + 1; m++) {
1299
+ V[m][m] = (2 * m - 1) * (x0 * V[m - 1][m - 1] - y0 * W[m - 1][m - 1]);
1300
+ W[m][m] = (2 * m - 1) * (x0 * W[m - 1][m - 1] + y0 * V[m - 1][m - 1]);
1301
+ if (m <= nMax) {
1302
+ V[m + 1][m] = (2 * m + 1) * z0 * V[m][m];
1303
+ W[m + 1][m] = (2 * m + 1) * z0 * W[m][m];
1304
+ }
1305
+ for (let n = m + 2; n <= nMax + 1; n++) {
1306
+ V[n][m] = ((2 * n - 1) * z0 * V[n - 1][m] - (n + m - 1) * rho * V[n - 2][m]) / (n - m);
1307
+ W[n][m] = ((2 * n - 1) * z0 * W[n - 1][m] - (n + m - 1) * rho * W[n - 2][m]) / (n - m);
1308
+ }
1309
+ }
1310
+
1311
+ let ax = 0, ay = 0, az = 0;
1312
+ for (let n = 2; n <= nMax; n++) {
1313
+ const C0 = gravC[n][0];
1314
+ ax -= C0 * V[n + 1][1];
1315
+ ay -= C0 * W[n + 1][1];
1316
+ az -= (n + 1) * C0 * V[n + 1][0];
1317
+ for (let m = 1; m <= n; m++) {
1318
+ const C = gravC[n][m], S = gravS[n][m];
1319
+ const fac = (n - m + 2) * (n - m + 1);
1320
+ ax += 0.5 * ((-C * V[n + 1][m + 1] - S * W[n + 1][m + 1]) +
1321
+ fac * (C * V[n + 1][m - 1] + S * W[n + 1][m - 1]));
1322
+ ay += 0.5 * ((-C * W[n + 1][m + 1] + S * V[n + 1][m + 1]) +
1323
+ fac * (-C * W[n + 1][m - 1] + S * V[n + 1][m - 1]));
1324
+ az += (n - m + 1) * (-C * V[n + 1][m] - S * W[n + 1][m]);
1325
+ }
1326
+ }
1327
+ const k = MU_MOON / (R * R);
1328
+ out[0] = ax * k; out[1] = ay * k; out[2] = az * k;
1329
+ }
1330
+
1331
+ /* The Moon's sidereal spin (= its orbital rate, tidal lock), about the
1332
+ scene's +Y pole. The integrator runs in this rotating Moon-fixed frame,
1333
+ so the gravity map stays locked to the surface and Earth stays at +X. */
1334
+ const MOON_SPIN = (2 * Math.PI) / (27.321661 * 86400); // rad/s
1335
 
1336
  // Integrated state in a Moon-centered frame, kilometres and km/s. The
1337
  // axes match the render frame used by computeSatPosition (+Y = Moon pole,
 
1340
  let perturbTrail = []; // recent positions (world units) for the evolving path
1341
  const TRAIL_MAX = 1400;
1342
 
1343
+ function perturbationsOn() { return pert.earth || pert.sun || pert.moonField; }
1344
 
1345
  /* Seed the integrator's position+velocity from the current Keplerian
1346
  elements, so turning perturbations on continues smoothly from the
 
1380
  function reseedSatState() {
1381
  const s = stateFromElements();
1382
  satState.pos.copy(s.pos);
1383
+ // The elements describe the orbit in inertial space at this instant;
1384
+ // convert to the rotating Moon-fixed frame: v_rot = v_inertial − ω × r,
1385
+ // with ω = (0, Ω, 0) so ω × r = (Ω·z, 0, −Ω·x).
1386
+ satState.vel.set(
1387
+ s.vel.x - MOON_SPIN * s.pos.z,
1388
+ s.vel.y,
1389
+ s.vel.z + MOON_SPIN * s.pos.x
1390
+ );
1391
  satState.active = perturbationsOn();
1392
+ satState.crashed = false;
1393
  perturbTrail = [];
1394
+ updatePerturbReadout();
1395
  }
1396
 
1397
+ /* Total acceleration (km/s²) on the satellite in the rotating Moon-fixed
1398
+ frame, given position (km) and velocity (km/s) in that frame. */
1399
  const _acc = new THREE.Vector3();
1400
  const _sb = new THREE.Vector3();
1401
  const _rel = new THREE.Vector3();
1402
+ const _hAcc = [0, 0, 0];
1403
+ function orbitAcceleration(posKm, velKms) {
1404
+ // Moon central term (point mass, n = 0).
1405
  const r = posKm.length();
1406
  _acc.copy(posKm).multiplyScalar(-MU_MOON / (r * r * r));
1407
+ // GRAIL gravity map (n ≥ 2). Scene → Moon-fixed body axes:
1408
+ // xb = x (0°E), yb = −z (90°E), zb = y (north pole).
1409
+ if (pert.moonField) {
1410
+ harmonicAccelBody(posKm.x, -posKm.z, posKm.y, _hAcc);
1411
+ _acc.x += _hAcc[0];
1412
+ _acc.y += _hAcc[2];
1413
+ _acc.z -= _hAcc[1];
1414
+ }
1415
+ // Rotating-frame terms: Coriolis −2ω×v and centrifugal −ω×(ω×r).
1416
+ const W = MOON_SPIN, W2 = W * W;
1417
+ _acc.x += -2 * W * velKms.z + W2 * posKm.x;
1418
+ _acc.z += 2 * W * velKms.x + W2 * posKm.z;
1419
  // Third bodies: direct (on satellite) minus indirect (on the Moon).
1420
  const addBody = (dirUnit, distKm, mu) => {
1421
  _sb.copy(dirUnit).multiplyScalar(distKm); // body position (km)
 
1438
  const _k3a = new THREE.Vector3(), _k4a = new THREE.Vector3();
1439
  const _tmp = new THREE.Vector3();
1440
  function integrateSatState(seconds) {
1441
+ if (seconds <= 0 || satState.crashed) return;
1442
  // Keep each RK4 step under ~1/400 of the orbital period for accuracy.
1443
  const period = 2 * Math.PI * Math.sqrt((orbit.a ** 3) / MU_MOON);
1444
  const maxStep = period / 400;
 
1447
  for (let step = 0; step < nSteps; step++) {
1448
  const p = satState.pos, v = satState.vel;
1449
  _k1v.copy(v);
1450
+ _k1a.copy(orbitAcceleration(p, _k1v));
1451
  _tmp.copy(p).addScaledVector(_k1v, dt / 2);
1452
  _k2v.copy(v).addScaledVector(_k1a, dt / 2);
1453
+ _k2a.copy(orbitAcceleration(_tmp, _k2v));
1454
  _tmp.copy(p).addScaledVector(_k2v, dt / 2);
1455
  _k3v.copy(v).addScaledVector(_k2a, dt / 2);
1456
+ _k3a.copy(orbitAcceleration(_tmp, _k3v));
1457
  _tmp.copy(p).addScaledVector(_k3v, dt);
1458
  _k4v.copy(v).addScaledVector(_k3a, dt);
1459
+ _k4a.copy(orbitAcceleration(_tmp, _k4v));
1460
  p.addScaledVector(_k1v, dt / 6).addScaledVector(_k2v, dt / 3)
1461
  .addScaledVector(_k3v, dt / 3).addScaledVector(_k4v, dt / 6);
1462
  v.addScaledVector(_k1a, dt / 6).addScaledVector(_k2a, dt / 3)
1463
  .addScaledVector(_k3a, dt / 3).addScaledVector(_k4a, dt / 6);
1464
+ // Impact check: a low orbit can be pulled into the surface by mascons.
1465
+ if (p.length() <= MOON_RADIUS_KM) {
1466
+ p.setLength(MOON_RADIUS_KM);
1467
+ v.set(0, 0, 0);
1468
+ satState.crashed = true;
1469
+ updatePerturbReadout();
1470
+ return;
1471
+ }
1472
  }
1473
  }
1474
 
 
1969
  bindNum("s-argp", "n-argp", (v) => { orbit.argp = v; elemChanged(); });
1970
  bindNum("s-nu", "n-nu", (v) => { orbit.nu = v; elemChanged(); });
1971
 
1972
+ // GRAIL gravity-map truncation degree (2 … GRAIL_MAX_DEGREE).
1973
+ bindNum("s-gdeg", "n-gdeg", (v) => { gravDegree = Math.round(v); updatePerturbReadout(); });
1974
+
1975
  // L2 halo controls
1976
  bindNum("s-l2amp", "n-l2amp", (v) => { l2.amp = v; updateOrbitLine(); positionSatellite(); });
1977
  bindNum("s-l2phase", "n-l2phase", (v) => { l2.phase = v; positionSatellite(); });
grail_gravity.js ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* GRAIL lunar gravity field, GRGM1200A (NASA GSFC, Goossens et al. 2016/2020),
2
+ fully-normalized spherical-harmonic coefficients [n, m, Cbar, Sbar],
3
+ truncated to degree 18. Source: PDS Geosciences node,
4
+ grail_1001/shadr/gggrx_1200a_sha.tab. Principal-axis, Moon-fixed frame. */
5
+ export const GRAIL_REF_RADIUS_KM = 1738;
6
+ export const GRAIL_GM = 4902.8001224453;
7
+ export const GRAIL_MAX_DEGREE = 18;
8
+ export const GRAIL_COEFFS = [
9
+ [2, 0, -0.00009088433935, 0],
10
+ [2, 1, 1.466412355e-11, 1.173276423e-9],
11
+ [2, 2, 0.00003467309647, 9.079189834e-10],
12
+ [3, 0, -0.000003197330808, 0],
13
+ [3, 1, 0.00002636800662, 0.000005454545636],
14
+ [3, 2, 0.0000141715288, 0.000004878036579],
15
+ [3, 3, 0.00001227520837, -0.000001774222183],
16
+ [4, 0, 0.000003234780844, 0],
17
+ [4, 1, -0.000006013483184, 0.00000166431982],
18
+ [4, 2, -0.000007116162106, -0.000006777047154],
19
+ [4, 3, -0.00000134986984, -0.00001344497658],
20
+ [4, 4, -0.000006006962116, 0.000003926413038],
21
+ [5, 0, -2.237853136e-7, 0],
22
+ [5, 1, -0.000001011595994, -0.000004118907857],
23
+ [5, 2, 0.000004399523587, 0.00000105713908],
24
+ [5, 3, 4.661372223e-7, 0.000008698881974],
25
+ [5, 4, 0.000002754254149, 6.767751522e-8],
26
+ [5, 5, 0.000003110551739, -0.000002754411168],
27
+ [6, 0, 0.000003818428233, 0],
28
+ [6, 1, 0.000001528258787, -0.000002599595389],
29
+ [6, 2, -0.000004397305292, -0.000002167691818],
30
+ [6, 3, -0.000003317509585, -0.000003427424471],
31
+ [6, 4, 3.412360154e-7, -0.000004058055887],
32
+ [6, 5, 0.000001454417194, -0.00001034177786],
33
+ [6, 6, -0.000004684225967, 0.000007229854566],
34
+ [7, 0, 0.000005593413663, 0],
35
+ [7, 1, 0.000007471669138, -1.197326905e-7],
36
+ [7, 2, -6.501483956e-7, 0.00000241110721],
37
+ [7, 3, 5.994191688e-7, 0.000002357327408],
38
+ [7, 4, -8.436741776e-7, 7.565274665e-7],
39
+ [7, 5, -2.068618509e-7, 0.000001069314367],
40
+ [7, 6, -0.00000106523323, 0.000001100497296],
41
+ [7, 7, -0.000001820446809, -0.000001600259228],
42
+ [8, 0, 0.0000023468287, 0],
43
+ [8, 1, 4.168354557e-9, 0.000001098037993],
44
+ [8, 2, 0.000003009312188, 0.00000193057394],
45
+ [8, 3, -0.000001889039921, 9.544758082e-7],
46
+ [8, 4, 0.000003408693289, -5.282503699e-7],
47
+ [8, 5, -0.000001248064605, 0.000002918561362],
48
+ [8, 6, -0.000001660418, -0.000002114682857],
49
+ [8, 7, -0.000001509689866, 0.000003268855602],
50
+ [8, 8, -0.000002485684524, 0.00000211634696],
51
+ [9, 0, -0.000003530909046, 0],
52
+ [9, 1, 0.000001866977478, 8.104274248e-8],
53
+ [9, 2, 0.000001927810657, -0.000001387562619],
54
+ [9, 3, -0.000001992423899, 0.000002201754297],
55
+ [9, 4, -0.00000188442899, -0.000001425794651],
56
+ [9, 5, -0.000001562527141, -0.00000352468129],
57
+ [9, 6, -0.000002127198581, -0.000003002612568],
58
+ [9, 7, -0.000003914823875, -1.068838742e-7],
59
+ [9, 8, -0.000001311981232, -0.00000220345427],
60
+ [9, 9, -9.381997958e-7, 0.000002488139704],
61
+ [10, 0, -0.000001069295708, 0],
62
+ [10, 1, 8.416001775e-7, -9.540712129e-7],
63
+ [10, 2, 3.572438248e-7, -2.651124194e-7],
64
+ [10, 3, 4.841989125e-7, 6.688370965e-7],
65
+ [10, 4, -0.00000357297054, 0.000001578913929],
66
+ [10, 5, 6.997015289e-7, -3.145793433e-7],
67
+ [10, 6, -1.272920943e-7, -0.000002095297208],
68
+ [10, 7, -0.000003998644544, -9.107481458e-7],
69
+ [10, 8, -0.000003559435874, 0.000002848851233],
70
+ [10, 9, -0.000004753152477, -5.154737479e-8],
71
+ [10, 10, 9.479302991e-7, -0.000001719393478],
72
+ [11, 0, -8.852086152e-7, 0],
73
+ [11, 1, -1.946262047e-8, 6.142454174e-7],
74
+ [11, 2, 6.995223853e-7, -0.000001968045189],
75
+ [11, 3, 4.084188653e-7, 7.362656193e-7],
76
+ [11, 4, -0.000001086769531, 0.000002190871496],
77
+ [11, 5, 5.032110233e-8, 0.000002588024114],
78
+ [11, 6, 5.243366622e-7, -0.00000136700016],
79
+ [11, 7, -8.452895736e-8, -0.000002841098304],
80
+ [11, 8, -0.000002095278802, -3.829447954e-7],
81
+ [11, 9, -0.000002334874262, 2.526360822e-7],
82
+ [11, 10, -0.000004680589101, -1.736319482e-7],
83
+ [11, 11, -0.000002888804009, -0.000001746400119],
84
+ [12, 0, -0.000002012260517, 0],
85
+ [12, 1, -7.068757573e-7, 0.000001647789802],
86
+ [12, 2, -1.052102123e-7, 0.000001507817403],
87
+ [12, 3, 8.557075772e-7, -0.00000405895501],
88
+ [12, 4, 8.130152955e-7, -3.446069784e-7],
89
+ [12, 5, 2.129514881e-10, 8.936261051e-7],
90
+ [12, 6, 0.00000108906869, 5.452465771e-7],
91
+ [12, 7, 0.00000214000057, -9.675522571e-7],
92
+ [12, 8, 3.985698162e-7, -0.000002206534003],
93
+ [12, 9, -0.000001345183546, 0.000001095024819],
94
+ [12, 10, -0.000003075479468, -0.000001273935079],
95
+ [12, 11, -9.818266795e-7, -3.284593199e-7],
96
+ [12, 12, 3.027612614e-7, 0.000001246894016],
97
+ [13, 0, 2.56486275e-7, 0],
98
+ [13, 1, 0.000001354459859, -7.666399896e-8],
99
+ [13, 2, -0.00000342523895, 3.839610029e-7],
100
+ [13, 3, -4.333415976e-7, -0.000001456310761],
101
+ [13, 4, 7.772680567e-7, -5.819234704e-7],
102
+ [13, 5, -0.000001186350443, 0.00000102133699],
103
+ [13, 6, -2.767673663e-8, 0.000001384237971],
104
+ [13, 7, -1.621318744e-7, -6.726680607e-7],
105
+ [13, 8, -2.922825112e-7, -0.000001210524961],
106
+ [13, 9, -1.699283279e-7, 5.275008753e-7],
107
+ [13, 10, -6.743046895e-7, 4.528616985e-7],
108
+ [13, 11, -0.000001305697192, 4.390463209e-7],
109
+ [13, 12, -5.743834119e-7, -0.00000152235166],
110
+ [13, 13, 0.000002499413969, -0.000002668796652],
111
+ [14, 0, 4.922537529e-7, 0],
112
+ [14, 1, 5.654274906e-7, -6.821060473e-7],
113
+ [14, 2, 3.644188734e-7, 3.552114427e-7],
114
+ [14, 3, 5.578909376e-7, 1.679989757e-7],
115
+ [14, 4, -3.905251308e-7, -0.000002582063472],
116
+ [14, 5, -7.823883299e-7, -2.159994714e-7],
117
+ [14, 6, -6.096177446e-7, 0.000001862283317],
118
+ [14, 7, -5.15427012e-7, 0.000001161510608],
119
+ [14, 8, 3.061477636e-7, 4.414688601e-7],
120
+ [14, 9, 8.051041404e-8, -0.000001638036641],
121
+ [14, 10, -7.782119897e-7, 5.930328292e-7],
122
+ [14, 11, -0.000001928511957, 0.000001937219876],
123
+ [14, 12, -0.000001448544228, -5.395014118e-7],
124
+ [14, 13, -3.214097849e-7, -0.000001017799197],
125
+ [14, 14, -6.135141841e-7, 0.000001071094098],
126
+ [15, 0, -2.280910373e-7, 0],
127
+ [15, 1, -7.975291281e-7, 3.536186471e-7],
128
+ [15, 2, -5.401530501e-8, 7.44655785e-7],
129
+ [15, 3, -0.000001378243699, -6.307093327e-7],
130
+ [15, 4, -9.560530691e-7, -0.000001323373609],
131
+ [15, 5, 7.737642944e-9, -8.933911518e-7],
132
+ [15, 6, -6.441733012e-8, -3.306666953e-7],
133
+ [15, 7, 0.000001125277825, 0.000001489415445],
134
+ [15, 8, 0.000001315084953, 0.000001886561516],
135
+ [15, 9, -8.519311826e-8, -0.000001011630531],
136
+ [15, 10, -6.015947013e-8, 4.227151772e-7],
137
+ [15, 11, -0.000001426273631, -0.000001502441816],
138
+ [15, 12, -0.000001767212301, -4.717907047e-7],
139
+ [15, 13, -4.049272056e-7, 3.09507418e-7],
140
+ [15, 14, 8.234663694e-7, 5.61453814e-7],
141
+ [15, 15, 5.483979738e-7, 7.778712572e-7],
142
+ [16, 0, 5.568507056e-7, 0],
143
+ [16, 1, 1.155900208e-7, 8.252511951e-7],
144
+ [16, 2, 0.00000145523454, 7.655552734e-9],
145
+ [16, 3, -1.942728872e-7, 5.233353564e-7],
146
+ [16, 4, 6.859523625e-7, 3.124412874e-7],
147
+ [16, 5, 7.634285197e-7, -6.484839858e-7],
148
+ [16, 6, 7.298090628e-7, -7.280730879e-7],
149
+ [16, 7, -2.807006605e-7, -5.804000253e-7],
150
+ [16, 8, 2.371405876e-8, 3.200971716e-7],
151
+ [16, 9, -7.806750148e-7, -8.233660949e-7],
152
+ [16, 10, 2.272160722e-7, 3.356479761e-8],
153
+ [16, 11, -3.314713065e-7, 7.721899806e-7],
154
+ [16, 12, -0.000001294188047, 9.158356414e-7],
155
+ [16, 13, -1.798967059e-7, -1.630011565e-7],
156
+ [16, 14, -6.798851339e-7, 1.776103191e-7],
157
+ [16, 15, -3.647552696e-7, -0.00000101580363],
158
+ [16, 16, -9.05345374e-7, -9.187907819e-7],
159
+ [17, 0, -0.00000103303107, 0],
160
+ [17, 1, 5.020203138e-7, 7.626026942e-8],
161
+ [17, 2, -2.907235605e-7, -8.725840949e-7],
162
+ [17, 3, -2.676950756e-8, -5.022520466e-7],
163
+ [17, 4, 0.000001285118198, 0.000002037548506],
164
+ [17, 5, 1.906641237e-7, -6.042887195e-7],
165
+ [17, 6, 7.21245314e-7, -0.000001245854682],
166
+ [17, 7, -0.000001298780679, -0.000001556269103],
167
+ [17, 8, -2.114574783e-7, -4.704485367e-7],
168
+ [17, 9, 3.282212813e-7, 0.000001371643583],
169
+ [17, 10, 4.162785682e-7, 6.136972884e-7],
170
+ [17, 11, 0.000001143966325, -2.020026698e-7],
171
+ [17, 12, 9.594684217e-7, 1.795588843e-7],
172
+ [17, 13, -3.972402897e-8, -2.222950281e-7],
173
+ [17, 14, 4.031243785e-7, 3.045648384e-7],
174
+ [17, 15, -6.430611857e-8, -5.045858731e-7],
175
+ [17, 16, -3.169487536e-7, -2.515117866e-7],
176
+ [17, 17, -3.808105589e-7, 0.000001504751002],
177
+ [18, 0, -5.203180376e-7, 0],
178
+ [18, 1, 3.604173623e-7, 2.683947225e-8],
179
+ [18, 2, -3.166166372e-7, -7.261188944e-7],
180
+ [18, 3, 9.952247727e-7, 4.326753577e-7],
181
+ [18, 4, -8.030660559e-7, 0.000001091315723],
182
+ [18, 5, -5.193010196e-7, 7.319151326e-8],
183
+ [18, 6, -0.000001701311091, 7.338974773e-7],
184
+ [18, 7, -2.182982473e-7, -0.000001133725984],
185
+ [18, 8, 4.445937258e-7, 2.868093193e-7],
186
+ [18, 9, 5.507298817e-7, -6.373990758e-7],
187
+ [18, 10, 3.581960219e-7, -5.500996079e-7],
188
+ [18, 11, 4.212975816e-7, -0.000001297976381],
189
+ [18, 12, 8.308532243e-7, 2.347682553e-7],
190
+ [18, 13, -0.000001215842904, -1.001881524e-7],
191
+ [18, 14, 6.111314353e-8, -0.00000113204954],
192
+ [18, 15, 2.432223894e-7, -0.000001084453177],
193
+ [18, 16, 8.988188774e-7, -2.135834419e-7],
194
+ [18, 17, 0.000001230031687, -4.712529001e-7],
195
+ [18, 18, -2.097003202e-7, -2.851295469e-7],
196
+ ];
index.html CHANGED
@@ -4,7 +4,7 @@
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
  <title>Luna Maps — 3D Moon Explorer</title>
7
- <link rel="stylesheet" href="style.css?v=15" />
8
  </head>
9
  <body>
10
  <div id="app">
@@ -144,6 +144,14 @@
144
  target="_blank" rel="noopener noreferrer">
145
  NASA SVS — LRO Moon 3D Models (topography) ↗
146
  </a>
 
 
 
 
 
 
 
 
147
  </div>
148
  </details>
149
 
@@ -162,14 +170,15 @@
162
  <li><b>three.js</b> (r160) — WebGL scene, meshes, camera and the
163
  picture-in-picture satellite view.</li>
164
  <li>Plain <b>HTML / CSS / JavaScript</b> (ES modules), no build
165
- step. The orbital mechanics live in <code>app.js</code>.</li>
 
166
  <li>Textures: NASA SVS CGI Moon Kit (LROC colour &amp; LOLA
167
  topography) and the USGS Unified Geologic Map.</li>
168
  </ul>
169
 
170
  <h4>Low lunar orbit — two-body (Kepler)</h4>
171
  <p>
172
- With Earth and Sun gravity off, the satellite follows a closed
173
  Keplerian ellipse about the Moon. Position comes from the six
174
  classical elements (a, e, i, Ω, ω, ν):
175
  </p>
@@ -192,10 +201,9 @@
192
 
193
  <h4>Perturbed orbit — Earth &amp; Sun gravity</h4>
194
  <p>
195
- Enabling Earth and/or Sun gravity switches to a numerical
196
- integrator (4th-order Runge–Kutta) seeded from the current
197
- Keplerian state. It propagates the equation of motion in a
198
- Moon-centred frame:
199
  </p>
200
  <p class="eq">
201
  r̈ = −μ·r/|r|³ + Σ&nbsp;μ_b·( (s_b−r)/|s_b−r|³ − s_b/|s_b|³ )
@@ -209,6 +217,34 @@
209
  398600.44&nbsp;km³/s², μ_Sun = 1.327×10¹¹&nbsp;km³/s².
210
  </p>
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  <h4>Sun &amp; Moon ephemeris (date/time)</h4>
213
  <p>
214
  The Sun direction (lighting / phase) and the Earth–Moon geometry
@@ -249,9 +285,10 @@
249
 
250
  <p class="disclaimer">
251
  Models are simplified for interactive visualisation. The ephemeris
252
- is low-precision, L2 is idealised, and the camera figures assume a
253
- nadir-pointing circular footprint — treat the numbers as
254
- educational estimates, not mission-grade values.
 
255
  </p>
256
  </div>
257
  </details>
@@ -317,6 +354,20 @@
317
  <input type="range" id="s-nu" min="0" max="360" step="1" value="0" />
318
  </div>
319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  <div class="map-toggle">
321
  <span class="cap">Earth gravity</span>
322
  <div class="toggle-buttons">
@@ -449,6 +500,6 @@
449
  }
450
  }
451
  </script>
452
- <script type="module" src="app.js?v=15"></script>
453
  </body>
454
  </html>
 
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
  <title>Luna Maps — 3D Moon Explorer</title>
7
+ <link rel="stylesheet" href="style.css?v=16" />
8
  </head>
9
  <body>
10
  <div id="app">
 
144
  target="_blank" rel="noopener noreferrer">
145
  NASA SVS — LRO Moon 3D Models (topography) ↗
146
  </a>
147
+ <a href="https://pgda.gsfc.nasa.gov/products/50"
148
+ target="_blank" rel="noopener noreferrer">
149
+ NASA GSFC — GRAIL lunar gravity field GRGM1200A ↗
150
+ </a>
151
+ <a href="https://science.nasa.gov/resource/grails-gravity-map-of-the-moon/"
152
+ target="_blank" rel="noopener noreferrer">
153
+ NASA — GRAIL's gravity map of the Moon ↗
154
+ </a>
155
  </div>
156
  </details>
157
 
 
170
  <li><b>three.js</b> (r160) — WebGL scene, meshes, camera and the
171
  picture-in-picture satellite view.</li>
172
  <li>Plain <b>HTML / CSS / JavaScript</b> (ES modules), no build
173
+ step. The orbital mechanics live in <code>app.js</code>; the
174
+ GRAIL coefficients in <code>grail_gravity.js</code>.</li>
175
  <li>Textures: NASA SVS CGI Moon Kit (LROC colour &amp; LOLA
176
  topography) and the USGS Unified Geologic Map.</li>
177
  </ul>
178
 
179
  <h4>Low lunar orbit — two-body (Kepler)</h4>
180
  <p>
181
+ With every perturbation off, the satellite follows a closed
182
  Keplerian ellipse about the Moon. Position comes from the six
183
  classical elements (a, e, i, Ω, ω, ν):
184
  </p>
 
201
 
202
  <h4>Perturbed orbit — Earth &amp; Sun gravity</h4>
203
  <p>
204
+ Enabling any perturbation switches to a numerical integrator
205
+ (4th-order Runge–Kutta) seeded from the current Keplerian state.
206
+ It propagates the equation of motion in a Moon-centred frame:
 
207
  </p>
208
  <p class="eq">
209
  r̈ = −μ·r/|r|³ + Σ&nbsp;μ_b·( (s_b−r)/|s_b−r|³ − s_b/|s_b|³ )
 
217
  398600.44&nbsp;km³/s², μ_Sun = 1.327×10¹¹&nbsp;km³/s².
218
  </p>
219
 
220
+ <h4>Moon gravity map — GRAIL</h4>
221
+ <p>
222
+ With "GRAIL gravity map" on, the Moon is no longer a point mass.
223
+ Its potential is expanded in spherical harmonics using NASA's
224
+ GRAIL model GRGM1200A (fully-normalized coefficients, truncated
225
+ to the selected degree, max 18):
226
+ </p>
227
+ <p class="eq">U = (μ/r) Σₙ Σₘ (R/r)ⁿ P̄ₙₘ(sin φ) (C̄ₙₘ cos mλ + S̄ₙₘ sin mλ)</p>
228
+ <p>
229
+ R = 1738.0&nbsp;km is the model's reference radius, φ/λ the
230
+ Moon-fixed latitude/longitude. The acceleration −∇U is evaluated
231
+ with the Cunningham V/W recursion (Montenbruck &amp; Gill). The
232
+ largest terms are the oblateness C̄₂₀ ≈ −9.09×10⁻⁵ and the
233
+ equatorial bulge C̄₂₂ ≈ 3.47×10⁻⁵; higher degrees add the large
234
+ basin mascons that make many low lunar orbits unstable.
235
+ </p>
236
+ <p>
237
+ Because the field is fixed to the surface, the perturbed orbit is
238
+ integrated in the rotating Moon-fixed frame (spin period
239
+ 27.32&nbsp;days), adding Coriolis and centrifugal terms:
240
+ </p>
241
+ <p class="eq">a_rot = a_grav − 2ω×v − ω×(ω×r)</p>
242
+ <p>
243
+ So the orbit plane slowly turns relative to the surface
244
+ (~13.2°/day). The integration stops if the orbit decays into the
245
+ surface.
246
+ </p>
247
+
248
  <h4>Sun &amp; Moon ephemeris (date/time)</h4>
249
  <p>
250
  The Sun direction (lighting / phase) and the Earth–Moon geometry
 
285
 
286
  <p class="disclaimer">
287
  Models are simplified for interactive visualisation. The ephemeris
288
+ is low-precision, the gravity map is truncated to degree 18, L2 is
289
+ idealised, and the camera figures assume a nadir-pointing circular
290
+ footprint — treat the numbers as educational estimates, not
291
+ mission-grade values.
292
  </p>
293
  </div>
294
  </details>
 
354
  <input type="range" id="s-nu" min="0" max="360" step="1" value="0" />
355
  </div>
356
 
357
+ <div class="map-toggle">
358
+ <span class="cap">Moon gravity</span>
359
+ <div class="toggle-buttons">
360
+ <button class="toggle-btn active" data-pmoon="off">Point mass</button>
361
+ <button class="toggle-btn" data-pmoon="on">GRAIL gravity map</button>
362
+ </div>
363
+ </div>
364
+ <div class="slider-row">
365
+ <label for="s-gdeg">Gravity map degree <span class="period-note">(GRGM1200A)</span>
366
+ <span class="num-wrap"><input type="number" id="n-gdeg" class="num-input" min="2" max="18" step="1" value="18" aria-label="GRAIL gravity field truncation degree" /></span>
367
+ </label>
368
+ <input type="range" id="s-gdeg" min="2" max="18" step="1" value="18" />
369
+ </div>
370
+
371
  <div class="map-toggle">
372
  <span class="cap">Earth gravity</span>
373
  <div class="toggle-buttons">
 
500
  }
501
  }
502
  </script>
503
+ <script type="module" src="app.js?v=16"></script>
504
  </body>
505
  </html>