Skip to content

wasmerio/sgp4

Repository files navigation

Sgp4 for WAPM


This repository is the port of the SGP4 library to WebAssembly.

Published package is available on WAPM.

Installation

  • WAPM
    $ wapm install dynamite-bud/sgp4
  • npm
    $ wapm install dynamite-bud/sgp4 --npm
  • pip
    $ wapm install dynamite-bud/sgp4 --pip

Usage with JavaScript

const { bindings } = require("@dynamite-bud/sgp4");
const {
  Elements,
  Constants,
} = require("@dynamite-bud/sgp4/src/bindings/sgp4/sgp4.js");

const resolveResult = ({ tag, val }) => (tag === "err" ? new Error(val) : val);
const wasm = await bindings.sgp4();
let response = await fetch(
  "https://celestrak.com/NORAD/elements/gp.php?GROUP=galileo&FORMAT=json"
);
let elementsArr = (await response.json()).map((e) =>
  resolveResult(Elements.fromJson(wasm, JSON.stringify(e)))
);
for (let elements of elementsArr) {
  console.log(elements.getObjectName());
  let constants = resolveResult(Constants.fromElements(wasm, elements));
  for (let hours of [12, 24]) {
    console.log(`    t = ${hours * 60} min`);
    let prediction = resolveResult(constants.propagate(parseFloat(hours * 60)));
    console.log(`        r = ${prediction.position} km`);
    console.log(`        ṙ = ${prediction.velocity} km.s⁻¹`);
  }
}

For more information, please refer to the sgp4 documentation.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE.md
MIT
LICENSE_MIT.md

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •