Entities with inertial reference frames still turning with the Earth

I’m using Satellite.js to propagate satellite orbits and display them using CesiumJS (I’m not using CZML). I calculate both the inertial positions and earth-fixed positions for each satellite over about 24 hours and add them to a SampledPositionProperty. Here’s a small sample of my code:

const totalSeconds = 60 * 60 * 6 * 2;
const timestepInSeconds = 10;
const start = new JulianDate(2460089, 46777.359);
const stop = JulianDate.addSeconds(start, totalSeconds, new JulianDate());
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();
viewer.timeline.zoomTo(start, stop);
viewer.clock.multiplier = 40;
viewer.clock.clockRange = ClockRange.LOOP_STOP;

let satellites = {};

const tle = "ISS (ZARYA)\n1 25544U 98067A   23152.06540943  .00016561  00000-0  29384-3 0  9992\n2 25544  51.6406  48.4580 0005212  41.1983 293.5437 15.50349995399283";
const satrec = satellite.twoline2satrec(tle.split('\n')[0].trim(), tle.split('\n')[1].trim());
const positionsOverTime = new SampledPositionProperty(ReferenceFrame.FIXED);
const intertialPositionsOverTime = new SampledPositionProperty(ReferenceFrame.INTERTIAL);

for (let j = 0; j < totalSeconds; j += timestepInSeconds) {
            const time = JulianDate.addSeconds(start, j, new JulianDate());
            const jsDate = JulianDate.toDate(time);

            const positionAndVelocity = satellite.propagate(satrec, jsDate);
            const gmst = satellite.gstime(jsDate);
            const p = satellite.eciToEcf(positionAndVelocity.position, gmst);

            const position = Cartesian3.fromElements(p.x *1000, p.y *1000, p.z * 1000);
            positionsOverTime.addSample(time, position);

            const pos = positionAndVelocity.position;
            const positionInertial =  Cartesian3.fromElements(pos.x * 1000, pos.y * 1000, pos.z * 1000);
            intertialPositionsOverTime.addSample(time, positionInertial);

const satellitePoint = viewer.entities.add({
        position: positionsOverTime,
        point: { pixelSize: 5, color: Color.RED }

It works fine for fixed coordinates (i.e. when I use position: positionsOverTime). When I try to use the inertial positions, inertialPositionsOverTime, the coordinates are correct for the starting time - however, as time goes on, the points/trajectory of the satellite moves with the earth (i.e. the satellite stays in the same place above the earth at all times, which shouldn’t happen). I was under the impression that using ReferenceFrame.INERTIAL would make it so that as the earth rotates, the entity will not move with the earth. This has been causing me issues for weeks now, and I can’t seem to find a solution - am I missing something? Any help would be greatly appreciated!

Hi @Jack2104, is that a direct copy from your code? There is a typo here:

const intertialPositionsOverTime = new SampledPositionProperty(ReferenceFrame.INTERTIAL);

The enum passed to SampledPositionProperty should be ReferenceFrame.INERTIAL. Since ReferenceFrame.INTERTIAL is undefined, SampledPositionProperty will default to ReferenceFrame.FIXED.

If this doesn’t solve your issue, would you be able to share a Sandcastle link or other complete code example?

I feel so dumb… that fixed it right away! Weeks of effort, for a single typo. Thank you so much :slight_smile:

No problem, I know the feeling :slight_smile:
I didn’t notice it myself until I copied ReferenceFrame.INTERTIAL into my VSCode search box, to see where else it was used in the code.

1 Like