Skip to content

Latest commit

 

History

History
62 lines (53 loc) · 2.17 KB

README.md

File metadata and controls

62 lines (53 loc) · 2.17 KB

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.