Permalink
Browse files

Date instance is supported as arguments of jday, gstimeFromDate and p…

…ropagate functions.
  • Loading branch information...
1 parent 68acd76 commit 6bff0a99a57481c68690a0f62e350d2ff192e093 @ezze ezze committed Sep 9, 2016
Showing with 95 additions and 29 deletions.
  1. +24 −9 dist/satellite.js
  2. +5 −5 dist/satellite.js.map
  3. +1 −1 dist/satellite.min.js
  4. +10 −0 src/gstime/jday.js
  5. +5 −3 src/propagate/propagate.js
  6. +3 −2 src/satellite.js
  7. +47 −9 test/satellite.spec.js
View
@@ -627,9 +627,10 @@ define('coordinate-transforms/topocentric-to-look-angles',[
/**
* @param {Object} topocentric
- * @param {Number} topocentric.topS
- * @param {Number} topocentric.topE
- * @param {Number} topocentric.topZ
+ * @param {Number} topocentric.topS Positive horizontal vector S due south.
+ * @param {Number} topocentric.topE Positive horizontal vector E due east.
+ * @param {Number} topocentric.topZ Vector Z normal to the surface of the earth (up).
+ * @returns {Object}
*/
return function(topocentric) {
var topS = topocentric.topS;
@@ -642,10 +643,11 @@ define('coordinate-transforms/topocentric-to-look-angles',[
return {
azimuth : Az,
elevation : El,
- rangeSat : rangeSat
+ rangeSat : rangeSat // Range in km.
};
};
});
+
/*
* satellite-js v1.2
* (c) 2013 Shashwat Kandadai and UCSC
@@ -891,6 +893,16 @@ define('gstime/jday',[], function() {
'use strict';
return function(year, mon, day, hr, minute, sec) {
+ if (year instanceof Date) {
+ var date = year;
+ year = date.getUTCFullYear();
+ mon = date.getUTCMonth() + 1; // Note, this function requires months in range 1-12.
+ day = date.getUTCDate();
+ hr = date.getUTCHours();
+ minute = date.getUTCMinutes();
+ sec = date.getUTCSeconds();
+ }
+
return (367.0 * year -
Math.floor((7 * (year + Math.floor((mon + 9) / 12.0))) * 0.25) +
Math.floor( 275 * mon / 9.0 ) +
@@ -1869,10 +1881,12 @@ define('propagate/propagate',[
) {
'use strict';
- return function propagate(satrec, year, month, day, hour, minute, second){
+ return function propagate() {
//Return a position and velocity vector for a given date and time.
- var j = jday(year, month, day, hour, minute, second);
- var m = (j - satrec.jdsatepoch) * constants.minutesPerDay;
+ var satrec = arguments[0],
+ date = Array.prototype.slice.call(arguments, 1),
+ j = jday.apply(null, date),
+ m = (j - satrec.jdsatepoch) * constants.minutesPerDay;
return sgp4(satrec, m);
};
});
@@ -3715,9 +3729,10 @@ define('satellite',[
dopplerFactor: dopplerFactor,
gstimeFromJday: gstime,
- gstimeFromDate: function(year, mon, day, hr, minute, sec) {
- return gstime(jday(year, mon, day, hr, minute, sec));
+ gstimeFromDate: function() {
+ return gstime(jday.apply(null, arguments));
},
+ jday: jday,
propagate: propagate,
twoline2satrec: twoline2satrec,
sgp4: sgp4
View
Oops, something went wrong.
Oops, something went wrong.
View
@@ -2,6 +2,16 @@ define([], function() {
'use strict';
return function(year, mon, day, hr, minute, sec) {
+ if (year instanceof Date) {
+ var date = year;
+ year = date.getUTCFullYear();
+ mon = date.getUTCMonth() + 1; // Note, this function requires months in range 1-12.
+ day = date.getUTCDate();
+ hr = date.getUTCHours();
+ minute = date.getUTCMinutes();
+ sec = date.getUTCSeconds();
+ }
+
return (367.0 * year -
Math.floor((7 * (year + Math.floor((mon + 9) / 12.0))) * 0.25) +
Math.floor( 275 * mon / 9.0 ) +
@@ -16,10 +16,12 @@ define([
) {
'use strict';
- return function propagate(satrec, year, month, day, hour, minute, second){
+ return function propagate() {
//Return a position and velocity vector for a given date and time.
- var j = jday(year, month, day, hour, minute, second);
- var m = (j - satrec.jdsatepoch) * constants.minutesPerDay;
+ var satrec = arguments[0],
+ date = Array.prototype.slice.call(arguments, 1),
+ j = jday.apply(null, date),
+ m = (j - satrec.jdsatepoch) * constants.minutesPerDay;
return sgp4(satrec, m);
};
});
View
@@ -52,9 +52,10 @@ define([
dopplerFactor: dopplerFactor,
gstimeFromJday: gstime,
- gstimeFromDate: function(year, mon, day, hr, minute, sec) {
- return gstime(jday(year, mon, day, hr, minute, sec));
+ gstimeFromDate: function() {
+ return gstime(jday.apply(null, arguments));
},
+ jday: jday,
propagate: propagate,
twoline2satrec: twoline2satrec,
sgp4: sgp4
@@ -7,7 +7,52 @@ define([
) {
'use strict';
+ function compareVectors(vector1, vector2, precision) {
+ precision = precision || 0;
+ if (precision === 0) {
+ expect(vector1.x).toBe(vector2.x);
+ expect(vector1.y).toBe(vector2.y);
+ expect(vector1.z).toBe(vector2.z);
+ }
+ else {
+ expect(vector1.x).toBeCloseTo(vector2.x, precision);
+ expect(vector1.y).toBeCloseTo(vector2.y, precision);
+ expect(vector1.z).toBeCloseTo(vector2.z, precision);
+ }
+ }
+
describe('Satellite test suite', function() {
+ it('Julian day', function() {
+ var now = new Date();
+ expect(satellite.jday(now)).toBe(satellite.jday(
+ now.getUTCFullYear(),
+ now.getUTCMonth() + 1,
+ now.getUTCDate(),
+ now.getUTCHours(),
+ now.getUTCMinutes(),
+ now.getUTCSeconds()
+ ));
+
+ var date = new Date(2016, 7, 22),
+ tleLine1 = '1 27424U 02022A 16235.86686911 .00000105 00000-0 33296-4 0 9990',
+ tleLine2 = '2 27424 98.2022 175.3843 0001285 39.9183 23.2024 14.57119903760831',
+ satrec = satellite.twoline2satrec(tleLine1, tleLine2);
+
+ var propagationByDate = satellite.propagate(satrec, date),
+ propagationByDateItems = satellite.propagate(
+ satrec,
+ date.getUTCFullYear(),
+ date.getUTCMonth() + 1,
+ date.getUTCDate(),
+ date.getUTCHours(),
+ date.getUTCMinutes(),
+ date.getUTCSeconds()
+ );
+
+ compareVectors(propagationByDate.position, propagationByDateItems.position);
+ compareVectors(propagationByDate.velocity, propagationByDateItems.velocity);
+ });
+
it('sgp4', function() {
var sgp4, sgp4dataItem,
satrec, result,
@@ -21,16 +66,9 @@ define([
for (var j = 0; j < sgp4dataItem.results.length; j += 1) {
result = sgp4dataItem.results[j];
-
sgp4 = satellite.sgp4(satrec, result.time);
-
- expect(sgp4.position.x).toBeCloseTo(result.position.x, precision);
- expect(sgp4.position.y).toBeCloseTo(result.position.y, precision);
- expect(sgp4.position.z).toBeCloseTo(result.position.z, precision);
-
- expect(sgp4.velocity.x).toBeCloseTo(result.velocity.x, precision);
- expect(sgp4.velocity.y).toBeCloseTo(result.velocity.y, precision);
- expect(sgp4.velocity.z).toBeCloseTo(result.velocity.z, precision);
+ compareVectors(sgp4.position, result.position, precision);
+ compareVectors(sgp4.velocity, result.velocity, precision);
}
}
});

0 comments on commit 6bff0a9

Please sign in to comment.