-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
executable file
·72 lines (60 loc) · 1.99 KB
/
utils.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
// General utilities, possibly used in many places
/*
import datetime as dt
import math as mt
import numscrypt as ns
*/
/*
// Universal synonyms for package-specific datatypes
typesGen = {'coordinate': 'float32', 'colorComponent': 'float32', 'index': 'uint32'}
typesNs = {'float32': ns.float32, 'int32': ns.int32}
*/
/*
// Return numscrypt column vector from entries
def colVec (*entries):
return ns.array (entries) .reshape (len (entries), 1)
*/
// Get radians from degrees
export function radFromDeg (degrees) {
var result = (degrees / 180) * Math.PI;
return result;
}
// Get degrees from radians
export function degFromRad (rad) {
return (rad / Math.PI) * 180;
}
export var obliquity = radFromDeg (23.43928)
export var sinObliq = Math.sin (obliquity)
export var cosObliq = Math.cos (obliquity)
// Get equatorial coords from ecliptic coords
export function equatFromEclipt (x, y, z) {
var result = [
x,
cosObliq * y - sinObliq * z,
sinObliq * y + cosObliq * z
];
return result;
}
/*
// Get right ascension and declination from x y z coords
export function raDecFromXyz (x, y, z):
return (
((12/Math.PI) * Math.atan2 (y, x) + 24) % 24,
(180/Math.PI) * Math.atan (z / Math.sqrt (x * x + y * y))
);
*/
// Convert <hours>.<minutes> to <hours>.<decimal fraction>
export function decimalHours (hoursMinutes) {
return Math.floor (hoursMinutes) + (100 / 60) * (hoursMinutes - Math.floor (hoursMinutes));
}
// Get julian day number from date and time, https://www.youtube.com/watch?v=_x1ga4dAzDo
export function julianDayNr (dateTime) {
a = (14 - dateTime.month) / 12;
y = dateTime.year + 4800 - a;
m = dateTime.month + 12 * a - 3;
jdnInt = dateTime.day + (153 * m + 2) / 5 + 365 * y + y/4 - y/100 + y/400 - 32045;
secPerDay = 24 * 3600;
sec = dateTime.hour * 3600 + dateTime.minute * 60 + dateTime.second;
frac = sec / secPerDay;
return jdnInt + frac;
}