OPEN SOURCE · 2025 · MIT LICENSE
sgp4/
A C99 SGP4/SDP4 satellite propagation library with no dynamic memory allocation — small enough to embed in firmware, and in the home page of this site.
- lang
- C99
- models
- SGP4 · SDP4 deep space
- memory
- no heap · fixed buffers
- size
- one .c + one .h
- tests
- 35 tests · 130 checks
- license
- MIT
## why
SGP4 is the standard model for predicting where a satellite will be from its two-line element set (TLE), and SDP4 extends it to deep-space orbits. The widely used reference implementation is David Vallado's, published by CelesTrak.
I wanted a version that drops into small systems: plain C99, no dynamic allocation, fixed-size buffers, and error codes instead of exceptions. The whole library is one source file and one header, so it can be copied into a project or pulled in with clib.
sgp4_tle_t tle;
sgp4_parse_tle_2line(line1, line2, &tle);
sgp4_elements_t elements;
sgp4_tle_to_elements(&tle, &elements);
sgp4_state_t state;
sgp4_init(&state, &elements);
sgp4_result_t result;
sgp4_propagate(&state, tsince_min, &result); /* km and km/s, TEME frame */
## design
- No heap. Every structure (
sgp4_tle_t,sgp4_state_t,sgp4_result_t, and the rest) is a fixed-size value the caller owns, so the library works wheremallocis unavailable or unwelcome. - Near-earth and deep-space. Initialization picks SGP4 or SDP4 from the orbital period, so the same calls handle low-earth and deep-space orbits.
- More than propagation. TLE parsing, checksum validation, and formatting, plus the coordinate transforms needed to use the result: ECI to ECEF, ECEF to geodetic, and look angles for pointing an antenna.
- Runs in the browser. The satellite tracker on this site's home page is this library compiled to WebAssembly, fed live elements from CelesTrak.
## how it was built
I had Claude Code port CelesTrak's Vallado reference implementation to C99. The test suite checks the math helpers, TLE parsing against real ISS and Vanguard elements, propagation at epoch and over a full orbit, and round trips through each coordinate transform. It builds warning-free with -std=c99 -Wall -Wextra -pedantic.
My C++ satellite tracker, SatTrack, has its own SGP4 port; this library is the standalone C version.