Skip to content

Commit

Permalink
Replaced the use of satellite.js and fixed handling of TEME frame
Browse files Browse the repository at this point in the history
  • Loading branch information
vsr83 committed Feb 18, 2024
1 parent e04348c commit 1deee91
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 82 deletions.
7 changes: 6 additions & 1 deletion GUI/ListDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ ListEnter.onclick = function()

const tleLine1 = lines[indElem * 3 + 1];
const tleLine2 = lines[indElem * 3 + 2];
const satrec = satellite.twoline2satrec(tleLine1, tleLine2);

const tle = sgp4.tleFromLines([
lines[indElem * 3],
lines[indElem * 3 + 1],
lines[indElem * 3 + 2]]);
const satrec = sgp4.createTarget(tle);

satellites.push(satrec);
satLines.push([title, tleLine1, tleLine2]);
Expand Down
5 changes: 4 additions & 1 deletion GUI/TLEDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ TLEEnter.onclick = function()
if (line1.startsWith('1') && line2.startsWith('2'))
{
osvControls.targetName.setValue(targetName);
satrec = satellite.twoline2satrec(lines[1], lines[2]);

const tle = sgp4.tleFromLines(lines);
satrec = sgp4.createTarget(tle);

osvControls.source.setValue('TLE');
updateTLEControls(targetName, line1, line2);
}
Expand Down
104 changes: 58 additions & 46 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var pointShaders = null;
var tleLine1 = '1 25544U 98067A 21356.70730882 .00006423 00000+0 12443-3 0 9993',
tleLine2 = '2 25544 51.6431 130.5342 0004540 343.5826 107.2903 15.49048054317816';
// Initialize a satellite record
var satrec = satellite.twoline2satrec(tleLine1, tleLine2);
var satrec = sgp4.tleFromLines([
"ISS (ZARYA) ", tleLine1, tleLine2]);

// Semi-major and semi-minor axes of the WGS84 ellipsoid.
var a = 6378.1370;
Expand Down Expand Up @@ -123,25 +124,34 @@ function drawScene(time)
// overwritten below.
ISS.osv = createOsv(today);

let osvSatListJ2000 = [];
let osvSatListTeme = [];
if (enableList)
{
for (let indSat = 0; indSat < satellites.length; indSat++)
{
const sat = satellites[indSat];
const positionAndVelocity = satellite.propagate(sat, today);
//const positionAndVelocity = satellite.propagate(sat, today);

// Propagate list items only once every 10 seconds to avoid CPU load.
let osvTeme;
try {
osvTeme = sgp4.propagateTargetTs(sat, today, 10.0);
} catch (err) {
continue;
}

// The position_velocity result is a key-value pair of ECI coordinates.
// These are the base results from which all other coordinates are derived.
const posEci = positionAndVelocity.position;
const velEci = positionAndVelocity.velocity;
const posEci = osvTeme.r;
const velEci = osvTeme.v;

if (typeof posEci !== 'undefined')
{
//console.log(posEci);
let osvSat = {r : [posEci.x * 1000.0, posEci.y * 1000.0, posEci.z * 1000.0],
v : [velEci.x * 1000.0, velEci.y * 1000.0, velEci.z * 1000.0],
ts: today};
osvSatListJ2000.push(osvSat);
let osvSat = {r : [osvTeme.r[0] * 1000.0, osvTeme.r[1] * 1000.0, osvTeme.r[2] * 1000.0],
v : [osvTeme.v[0] * 1000.0, osvTeme.v[1] * 1000.0, osvTeme.v[2] * 1000.0],
ts: today};
osvSatListTeme.push(osvSat);
}
}
}
Expand Down Expand Up @@ -253,10 +263,10 @@ function drawScene(time)

if (enableList)
{
for (let indSat = 0; indSat < osvSatListJ2000.length; indSat++)
for (let indSat = 0; indSat < osvSatListTeme.length; indSat++)
{
const rJ2000 = osvSatListJ2000[indSat].r;
pointsOut.push(MathUtils.vecmul(rJ2000, 0.001));
const rTeme = osvSatListTeme[indSat].r;
pointsOut.push(MathUtils.vecmul(rTeme, 0.001));
}
pointShaders.setGeometry(pointsOut);
}
Expand Down Expand Up @@ -298,15 +308,15 @@ function drawScene(time)
{
// Performance : It is significantly faster to perform the J2000->ECEF coordinate
// transformation in the vertex shader:
const rotMatrixJ2000 = createRotMatrix(today, JD, JT, nutPar);
const rotMatrixTeme = createRotMatrix(today, JD, JT, nutPar);

if (guiControls.frame === 'J2000')
{
pointShaders.draw(matrix);
}
else
{
pointShaders.draw(m4.multiply(matrix, m4.transpose(rotMatrixJ2000)));
pointShaders.draw(m4.multiply(matrix, m4.transpose(rotMatrixTeme)));
}
}

Expand All @@ -322,7 +332,7 @@ function drawScene(time)
}

/**
* Create rotation matrix for J2000 -> ECEF transformation for the point
* Create rotation matrix for TEME -> ECEF transformation for the point
* shader.
*
* @param {*} ts
Expand All @@ -341,9 +351,9 @@ function createRotMatrix(today, JD, JT, nutPar)
const osvVec1 = {r : [1, 0, 0], v : [0, 0, 0], JT : JT, JD : JD, ts : today};
const osvVec2 = {r : [0, 1, 0], v : [0, 0, 0], JT : JT, JD : JD, ts : today};
const osvVec3 = {r : [0, 0, 1], v : [0, 0, 0], JT : JT, JD : JD, ts : today};
let osvVec1_ECEF = Frames.osvJ2000ToECEF(osvVec1, nutPar);
let osvVec2_ECEF = Frames.osvJ2000ToECEF(osvVec2, nutPar);
let osvVec3_ECEF = Frames.osvJ2000ToECEF(osvVec3, nutPar);
let osvVec1_ECEF = sgp4.coordTemePef(osvVec1);
let osvVec2_ECEF = sgp4.coordTemePef(osvVec2);
let osvVec3_ECEF = sgp4.coordTemePef(osvVec3);
rotMatrixJ2000[0] = osvVec1_ECEF.r[0];
rotMatrixJ2000[1] = osvVec2_ECEF.r[0];
rotMatrixJ2000[2] = osvVec3_ECEF.r[0];
Expand Down Expand Up @@ -407,28 +417,30 @@ function createOsv(today)
osvControls.osvVz.setValue(osvOut.v[2]);
}
else if (guiControls.source === "TLE")
{
const positionAndVelocity = satellite.propagate(satrec, today);
// The position_velocity result is a key-value pair of ECI coordinates.
// These are the base results from which all other coordinates are derived.
const positionEci = positionAndVelocity.position;
const velocityEci = positionAndVelocity.velocity;

osvControls.osvX.setValue(positionEci.x);
osvControls.osvY.setValue(positionEci.y);
osvControls.osvZ.setValue(positionEci.z);
osvControls.osvVx.setValue(velocityEci.x * 1000.0);
osvControls.osvVy.setValue(velocityEci.y * 1000.0);
osvControls.osvVz.setValue(velocityEci.z * 1000.0);
{
let osvTeme;
try {
osvTeme = sgp4.propagateTargetTs(satrec, today, 0.0);
} catch (err) {
alert(err);
}
const osvJ2000 = sgp4.coordTemeJ2000(osvTeme);

osvControls.osvX.setValue(osvJ2000.r[0]);
osvControls.osvY.setValue(osvJ2000.r[1]);
osvControls.osvZ.setValue(osvJ2000.r[2]);
osvControls.osvVx.setValue(osvJ2000.v[0] * 1000.0);
osvControls.osvVy.setValue(osvJ2000.v[1] * 1000.0);
osvControls.osvVz.setValue(osvJ2000.v[2] * 1000.0);

osvOut = {r: [
positionEci.x * 1000.0,
positionEci.y * 1000.0,
positionEci.z * 1000.0],
osvJ2000.r[0] * 1000.0,
osvJ2000.r[1] * 1000.0,
osvJ2000.r[2] * 1000.0],
v: [
velocityEci.x * 1000.0,
velocityEci.y * 1000.0,
velocityEci.z * 1000.0],
osvJ2000.v[0] * 1000.0,
osvJ2000.v[1] * 1000.0,
osvJ2000.v[2] * 1000.0],
ts: today
};
osvControls.osvYear.setValue(today.getFullYear());
Expand Down Expand Up @@ -600,11 +612,11 @@ function drawOrbit(today, matrix, kepler_updated, nutPar)
let z = 0;
if (guiControls.source === "TLE")
{
const osvProp = satellite.propagate(satrec, deltaDate);
const posEci = osvProp.position;
const velEci = osvProp.velocity;
const osvPropJ2000 = {r : [posEci.x * 1000.0, posEci.y* 1000.0, posEci.z* 1000.0],
v : [velEci.x, velEci.y, velEci.z],
const osvTeme = sgp4.propagateTargetTs(satrec, deltaDate, 0.0);
const posEci = osvTeme.r;
const velEci = osvTeme.v;
const osvPropJ2000 = {r : [posEci[0] * 1000.0, posEci[1] * 1000.0, posEci[2] * 1000.0],
v : [velEci[0], velEci[1], velEci[2]],
ts : deltaDate};

if (guiControls.frame === 'ECEF')
Expand All @@ -614,7 +626,7 @@ function drawOrbit(today, matrix, kepler_updated, nutPar)
}
else if (guiControls.frame === 'J2000')
{
[x, y, z] = [posEci.x, posEci.y, posEci.z];
[x, y, z] = [posEci[0], posEci[1], posEci[2]];
}
}
else
Expand Down Expand Up @@ -693,7 +705,7 @@ function drawSun(lonlat, JT, JD, rASun, declSun, matrix, nutPar)

if (guiControls.frame === 'J2000')
{
sunPos = Frames.posECEFToCEP(JT, JD, sunPos);
sunPos = Frames.posECEFToCEP(JT, JD, sunPos, nutPar);
sunPos = Frames.posCEPToJ2000(JT, sunPos, nutPar);
}
let sunMatrix = m4.translate(matrix, sunPos[0] * 0.001, sunPos[1] * 0.001, sunPos[2] * 0.001);
Expand All @@ -709,7 +721,7 @@ function drawSun(lonlat, JT, JD, rASun, declSun, matrix, nutPar)

if (guiControls.frame === 'J2000')
{
rSubSolarDelta = Frames.posECEFToCEP(JT, JD, rSubSolarDelta);
rSubSolarDelta = Frames.posECEFToCEP(JT, JD, rSubSolarDelta, nutPar);
rSubSolarDelta = Frames.posCEPToJ2000(JT, rSubSolarDelta, nutPar);
}

Expand All @@ -734,7 +746,7 @@ function drawSun(lonlat, JT, JD, rASun, declSun, matrix, nutPar)

if (guiControls.frame === 'J2000')
{
rSubSolarDelta = Frames.posECEFToCEP(JT, JD, rSubSolarDelta);
rSubSolarDelta = Frames.posECEFToCEP(JT, JD, rSubSolarDelta, nutPar);
rSubSolarDelta = Frames.posCEPToJ2000(JT, rSubSolarDelta, nutPar);
}

Expand Down
6 changes: 4 additions & 2 deletions computation/Frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ Frames.posCEPToECEF = function(JT, JD, rCEP)
* Julian date.
* @param {*} rECEF
* Position in ECEF coordinates.
* @param {*} nutPar
* Nutation parameters.
* @returns Position in CEP frame.
*/
Frames.posECEFToCEP = function(JT, JD, rECEF)
Frames.posECEFToCEP = function(JT, JD, rECEF, nutPar)
{
let osv_ECEF = {};
let LST = TimeConversions.computeSiderealTime(0, JD, JT);
let LST = TimeConversions.computeSiderealTime(0, JD, JT, nutPar);
// Apply the Earth Rotation Matrix (A.32):
rCEP = MathUtils.rotZ(rECEF, LST);

Expand Down
31 changes: 0 additions & 31 deletions imports/satellite.min.js

This file was deleted.

1 change: 1 addition & 0 deletions imports/sgp4.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<script src="GUI/SelectDialog.js"></script>
<script src="GUI/Search.js"></script>

<script src="imports/satellite.min.js"></script>
<script src="imports/sgp4.js"></script>
<script src="imports/m4.js"></script>
<script src="imports/dat.gui.min.js"></script>
<script src="imports/WebGLUtils.js"></script>
Expand Down

0 comments on commit 1deee91

Please sign in to comment.