Course contentsShow

Module 03 · Lesson 3

Frame Transformations in Code

Converting inertial coordinates to Earth-fixed ones is mostly a rotation about the Earth's axis. This lesson builds a simplified version, shows the classic sign and frame errors, and explains why to use a library.

8 minute readUpdated November 23, 2026

Learning objectives

After this lesson you will be able to:

  • Rotate an inertial position into an approximate Earth-fixed position using the Earth rotation angle
  • Identify direction-of-rotation and frame-mixing errors, and design tests that expose them
  • Explain what the simplified transformation omits and why production code relies on vetted libraries and reference values

The Earth turns under the orbit

The previous lesson left a satellite in inertial coordinates and a ground station in Earth-fixed ones. To compare them, one must be converted to the other's frame. To a first approximation the two frames share a Z axis, the Earth's rotation axis, and differ by a single rotation about it. This lesson builds that approximation and then says precisely what it leaves out.

The Earth rotation angle

The Earth rotation angle is the angle through which the Earth has turned relative to a non-rotating reference direction. It is a linear function of time: a fixed value at the epoch J2000.0 plus a constant rate. The rate is about 360.9856 degrees per day. It exceeds 360 because the Earth completes one turn relative to the stars in about 23 hours 56 minutes, not 24 hours.

The time that goes into the formula must be UT1, the scale tied to the Earth's rotation. Using UTC instead introduces an error of up to 0.9 seconds of rotation, which is as much as about 400 meters at the equator.

An older, closely related quantity is Greenwich mean sidereal time, which measures the same rotation from the mean equinox. The two angles nearly coincide at J2000.0 and separate slowly afterward. Each belongs with a particular inertial frame: sidereal time with equinox-based frames such as TEME, and the Earth rotation angle with the current international conventions. Swapping them introduces an error that grows every year.

Rotation about the Z axis

With the angle known, the conversion is a rotation about Z. The Z component is unchanged, and the X and Y components mix through the sine and cosine of the angle.

type Vec3 = [number, number, number];
const DEG = Math.PI / 180; // radians per degree

/** Earth rotation angle in radians from a Julian date in UT1. */
function earthRotationAngle(jdUt1: number): number {
  const turns = 0.7790572732640 + 1.00273781191135448 * (jdUt1 - 2451545.0);
  return 2 * Math.PI * (turns - Math.floor(turns));
}

/**
 * Approximate ECI to ECEF. The axes turn eastward about +Z by theta (radians).
 * Ignores precession, nutation and polar motion.
 */
function eciToEcefApprox(rEci: Vec3, theta: number): Vec3 {
  const c = Math.cos(theta);
  const s = Math.sin(theta);
  const [x, y, z] = rEci;
  return [c * x + s * y, -s * x + c * y, z];
}

const fmt = (v: Vec3) => v.map((c) => c.toFixed(1)).join(", ");
const longitudeDeg = (v: Vec3) => Math.atan2(v[1], v[0]) / DEG;

// Sanity check: a point on the inertial X axis after the Earth has turned 90 degrees.
const check = eciToEcefApprox([7000, 0, 0], 90 * DEG);
console.log(fmt(check), `longitude ${longitudeDeg(check).toFixed(1)} deg`);

console.log(`angle at J2000.0: ${(earthRotationAngle(2451545.0) / DEG).toFixed(4)} deg`);
const theta = earthRotationAngle(2461368.0); // 2026-11-23 12:00 UT1
const r = eciToEcefApprox([7000, 0, 0], theta);
console.log(`angle ${(theta / DEG).toFixed(2)} deg -> ${fmt(r)}`);
console.log(`longitude ${longitudeDeg(r).toFixed(2)} deg`);

The output is:

0.0, -7000.0, 0.0 longitude -90.0 deg
angle at J2000.0: 280.4606 deg
angle 242.13 deg -> -3272.3, 6188.1, 0.0
longitude 117.87 deg

Direction-of-rotation mistakes

The sanity check deserves attention, because the sign of the sine terms is the most common error in this kind of code.

There are two ways to read "rotate by an angle". One turns a vector within fixed axes. The other turns the axes and re-expresses a vector that has not moved. The two matrices are transposes of each other, which means that the signs of the two sine terms are swapped. Here the axes turn. The Earth-fixed X axis, which passes through the prime meridian, moves eastward, so a point that is stationary in the inertial frame appears to move west, and its longitude decreases.

That is what the check shows. After the Earth has turned 90 degrees, a point on the inertial X axis is at longitude 90 degrees west, with Earth-fixed coordinates (0, -7000, 0). Code that returns (0, 7000, 0) has rotated the wrong way.

Other mistakes belong to the same family.

  • Round trips prove little. If the forward and inverse rotations share a sign error, converting there and back returns the input exactly.
  • Velocity needs more. Rotating a velocity vector is not enough, because the Earth-fixed frame is itself turning. The missing term is about half a kilometer per second in low Earth orbit.

What the simple version ignores

EffectWhat it isApproximate size
PrecessionSlow drift of the Earth's axis, about 50 arcseconds per yearAbout a third of a degree since 2000, tens of kilometers in low Earth orbit
NutationPeriodic wobble of the axisUp to roughly 20 arcseconds, several hundred meters in low Earth orbit
Polar motionMovement of the axis relative to the crustA few tenths of an arcsecond, about 10 meters on the ground

How much of this matters depends on the inertial frame at the input. TEME is defined by the equator of the current date, so precession and nutation are already largely accounted for. A single rotation by sidereal time is the standard route from SGP4 output to Earth-fixed coordinates, and it is well matched to the accuracy of SGP4 itself. Applying the same single rotation to J2000 or GCRF coordinates is not acceptable today, because the precession term alone is tens of kilometers.

Mixing frames

The classic frame bug is to treat SGP4 output as J2000. Both are called ECI. Both are arrays of three plausible numbers. Nothing crashes. The result is rotated by about a third of a degree, which shows up as tracks displaced by tens of kilometers and passes that are slightly mistimed.

The defense is the same as for time scales. Make the frame part of the type, so that a TEME vector cannot be passed where a GCRF vector is expected. Name functions for the frames they connect, such as temeToItrf. A name like eciToEcef hides exactly the information that matters.

Why production code uses a library

The full transformation between GCRF and ITRF is a chain of rotations for precession, nutation, the Earth's rotation and polar motion. It is defined by international conventions, depends on Earth orientation data published by the IERS, and has been revised more than once. Vetted implementations exist: the SOFA library of the International Astronomical Union, the SPICE toolkit from NASA's Navigation and Ancillary Information Facility, and open-source projects such as Orekit and Astropy.

The parallel is cryptography or time zone handling: use the reviewed implementation. The parallel is imperfect, because several correct conventions exist and the engineer still has to know which frame the data is in.

A library does not remove the need to test. Check the integration against published reference values, such as the validation cases supplied with SOFA or the test cases published with the SGP4 reference code. A test that compares the code with itself cannot detect a consistent error.

A practical example: a ground track that drifts the wrong way

A developer builds a ground track display. An SGP4 library supplies positions, and the developer writes a rotation to convert them to longitude and latitude. The display looks reasonable until someone notices that each orbit crosses the equator farther east than the one before. The foundation course established that the crossing point moves west, because the Earth turns eastward beneath the orbit.

The developer adds the X axis test from this lesson. It returns (0, 7000, 0). The sine terms have the wrong sign. With the sign corrected, the track steps westward, and a comparison with a trusted tracking source agrees to a small fraction of a degree.

A second developer then replaces the hand-written rotation with a library function documented as converting J2000 to ITRF. The track shifts by tens of kilometers. The function is correct. The input is TEME, not J2000. The team introduces separate types for each frame and converts the SGP4 output explicitly.

Both errors produced plausible pictures. A known geometric case caught the first, and an independent reference caught the second.

Module 4 turns from where things are to how an orbit is described and predicted, starting with the classical orbital elements.

Key takeaways

  • To first order, inertial and Earth-fixed coordinates differ by a rotation about the Z axis through an angle that grows by about 360.9856 degrees per day.
  • Rotating the axes by an angle and rotating a vector by the same angle are opposite operations. Confusing them flips the sign of the sine terms.
  • The simplified rotation ignores precession, nutation and polar motion, and it needs the UT1 time scale and the matching inertial frame.
  • Production code should call a vetted library and be tested against published reference values, not only against itself.

Knowledge check

Check your understanding. These questions are not graded and you can retry as often as you like.

Question 1 of 3· Select one answerA point lies on the inertial X axis at radius r, and the Earth rotation angle is 90 degrees. Using the simplified transformation, what are its Earth-fixed coordinates?
Question 2 of 3· Select all that applyWhich practices help to catch errors in frame transformation code? Select all that apply.
Question 3 of 3· Select one answerA service takes position vectors from SGP4 and passes them, unconverted, to a library function that expects J2000 coordinates. What happens?

0 of 3 questions answered.

Glossary

Earth rotation angle

The angle through which the Earth has turned about its axis relative to a non-rotating reference direction. It is a linear function of UT1.

Greenwich mean sidereal time

An older measure of the Earth's rotation, referred to the mean equinox. It is the rotation angle paired with equinox-based frames such as TEME.

Rotation matrix

A three-by-three matrix that converts the components of a vector from one set of axes to another, or rotates a vector within one set of axes.

Precession

The slow drift in the direction of the Earth's rotation axis, which traces a cone over about 26,000 years.

Nutation

A small periodic wobble of the Earth's rotation axis superimposed on precession, with a main period of about 18.6 years.

Polar motion

The small movement of the Earth's rotation axis relative to the planet's crust, amounting to a few tenths of an arcsecond.

References and further reading

Finished this lesson?

Loading your progress…

Lesson version 1.0.0.