Skip to content

Commit c212f66

Browse files
committed
refactor: simplify ECI-to-ECEF conversion in getAzEl to direct Rz(-GMST) rotation
Replace roundabout spherical decomposition (asin, atan2, 3x cos/sin) with equivalent matrix rotation (2x cos/sin). Same result, fewer ops, clearer intent.
1 parent e6c6458 commit c212f66

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/astro/az-el.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ export function getAzEl(
2222
): { az: number; el: number } {
2323
const DEG2RAD = Math.PI / 180;
2424

25-
const satR = Math.sqrt(eciX * eciX + eciY * eciY + eciZ * eciZ);
26-
if (satR === 0) return { az: 0, el: -90 };
25+
if (eciX === 0 && eciY === 0 && eciZ === 0) return { az: 0, el: -90 };
2726

28-
// Satellite geocentric lat/lon from ECI, then to ECEF
29-
const satLat = Math.asin(eciZ / satR);
30-
const satLonEci = Math.atan2(eciY, eciX);
31-
const satLonEcef = satLonEci - gmstRad;
32-
33-
const sx = satR * Math.cos(satLat) * Math.cos(satLonEcef);
34-
const sy = satR * Math.cos(satLat) * Math.sin(satLonEcef);
35-
const sz = satR * Math.sin(satLat);
27+
// ECI to ECEF via Rz(-GMST)
28+
const cg = Math.cos(gmstRad), sg = Math.sin(gmstRad);
29+
const sx = cg * eciX + sg * eciY;
30+
const sy = -sg * eciX + cg * eciY;
31+
const sz = eciZ;
3632

3733
// Observer ECEF position (WGS-84 ellipsoid)
3834
const obs = geodeticToEcef(obsLatDeg, obsLonDeg, obsAltM);

0 commit comments

Comments
 (0)