forked from max-mapper/equatorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (64 loc) · 1.58 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
module.exports.raDeg2Hms = function(ra, round) {
var prefix = ''
var deg = +ra
if (deg < 0) {
prefix = '-'
deg = Math.abs(deg)
}
var hour = Math.floor(deg / 15)
var min = Math.floor(((deg / 15) - hour) * 60)
var sec = ((((deg / 15) - hour) * 60) - min) * 60
if (round) sec = Math.floor(sec)
return prefix + [hour, min, sec].join(':')
}
module.exports.decDeg2Hms = function(dec, round) {
var prefix = ''
var deg = +dec
if (deg < 0) {
prefix = '-'
deg = Math.abs(deg)
}
var hour = Math.floor(deg)
var min = Math.abs(Math.floor((deg - hour) * 60))
var sec = (Math.abs((deg - hour) * 60) - min) * 60
if (round) sec = Math.floor(sec)
return prefix + [hour, min, sec].join(':')
}
module.exports.raHms2Deg = function(ra, round) {
var parts = ra.split(':')
var sign = 1
if (ra.toString()[0] === '-')
{
sign = -1
}
var h = parseFloat(parts[0])
var m = parseFloat(parts[1])
var s = parseFloat(parts[2])
if (h.toString()[0] === '-' || sign == -1) {
sign = -1
h = Math.abs(h)
}
var sDeg = (s / 240)
if (round) sDeg = Math.floor(sDeg)
deg = (h * 15) + (m / 4) + sDeg
return deg * sign
}
module.exports.decHms2Deg = function(dec, round) {
var parts = dec.split(':')
var sign = 1
if (dec.toString()[0] === '-')
{
sign = -1
}
var d = parseFloat(parts[0])
var m = parseFloat(parts[1])
var s = parseFloat(parts[2])
if (d.toString()[0] === '-' || sign == -1) {
sign = -1
d = Math.abs(d)
}
var sDeg = (s / 3600)
if (round) sDeg = Math.floor(sDeg)
var deg = d + (m / 60) + sDeg
return deg * sign
}