-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
142 lines (118 loc) · 4.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict'
var constant = require('./src/astronomy/moshier/constant')
var processor = require('./src/astronomy/moshier/processor')
var body = require('./src/astronomy/moshier/body')
function setUp (date, geodeticalLongitude, geodeticalLatitude, height) {
var d = !date ? new Date() : date
constant.tlong = geodeticalLongitude
constant.glat = geodeticalLatitude
constant.height = height
constant.date = {
day: d.getUTCDate(),
month: d.getUTCMonth()+1,
year: d.getUTCFullYear(),
hours: d.getUTCHours(),
minutes: d.getUTCMinutes(),
seconds: d.getUTCSeconds()
}
processor.init()
}
// Example call: getAllPlanets(new Date(), 10.0014, 53.5653, 0);
function getAllPlanets (date, geodeticalLongitude, geodeticalLatitude, height) {
setUp(date, geodeticalLongitude, geodeticalLatitude, height)
var ret = {
date: undefined,
observer: undefined,
observed: {}
}
date = constant.date
var observables = Object.keys(body)
for (var i = 0; i < observables.length; i++) {
var observeMe = observables[i]
if (['earth', 'init'].indexOf(observeMe) >= 0) {
continue
}
constant.body = body[observeMe]
processor.calc(date, constant.body)
if (ret.date === undefined) {
ret.date = {
gregorianTerrestrial: [date.day, date.month, date.year].join('.')
+ ' ' + [date.hours, date.minutes, date.seconds].join(':'),
gregorianTerrestrialRaw: date,
gregorianUniversal: constant.date.universalDateString,
gregorianDelta: '00:00:' + constant.date.delta,
julianTerrestrial: constant.date.julian,
julianUniversal: constant.date.universal,
julianDelta: constant.date.delta / 86400
}
}
if (ret.observer === undefined) {
ret.observer = {
name: 'earth',
longitudeGeodetic: constant.tlong,
longitudeGeocentric: constant.tlong,
latitudeGeodetic: constant.glat,
latitudeGeocentric: constant.tlat,
heightGeodetic: constant.height,
heightGeocentric: constant.trho * constant.aearth / 1000
}
}
ret.observed[constant.body.key] = {
name: constant.body.key,
raw: constant.body,
apparentLongitudeDms30: constant.body.position.apparentLongitude30String,
apparentLongitudeDms360: constant.body.position.apparentLongitudeString,
apparentLongitudeDd: constant.body.position.apparentLongitude,
geocentricDistanceKm: constant.body.position.geocentricDistance
}
}
return ret
}
// Example call: getPlanet('moon', new Date(), 10.0014, 53.5653, 0);
function getPlanet (planetName, date, geodeticalLongitude, geodeticalLatitude, height) {
setUp(date, geodeticalLongitude, geodeticalLatitude, height)
var ret = {
date: undefined,
observer: undefined,
observed: {}
}
date = constant.date
constant.body = body[planetName]
processor.calc(date, constant.body)
if (ret.date === undefined) {
ret.date = {
gregorianTerrestrial: [date.day, date.month, date.year].join('.')
+ ' ' + [date.hours, date.minutes, date.seconds].join(':'),
gregorianTerrestrialRaw: date,
gregorianUniversal: constant.date.universalDateString,
gregorianDelta: '00:00:' + constant.date.delta,
julianTerrestrial: constant.date.julian,
julianUniversal: constant.date.universal,
julianDelta: constant.date.delta / 86400
}
}
if (ret.observer === undefined) {
ret.observer = {
name: 'earth',
longitudeGeodetic: constant.tlong,
longitudeGeocentric: constant.tlong,
latitudeGeodetic: constant.glat,
latitudeGeocentric: constant.tlat,
heightGeodetic: constant.height,
heightGeocentric: constant.trho * constant.aearth / 1000
}
}
ret.observed[constant.body.key] = {
name: constant.body.key,
raw: constant.body,
apparentLongitudeDms30: constant.body.position.apparentLongitude30String,
apparentLongitudeDms360: constant.body.position.apparentLongitudeString,
apparentLongitudeDd: constant.body.position.apparentLongitude,
geocentricDistanceKm: constant.body.position.geocentricDistance
}
return ret
}
module.exports = {
getAllPlanets: getAllPlanets,
getPlanet: getPlanet
}