@math.gl/sun 3.6.0-alpha.1 → 3.6.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/index.js +2 -2
- package/dist/es5/suncalc.js +32 -32
- package/dist/es5/suncalc.js.map +1 -1
- package/package.json +2 -2
package/dist/es5/index.js
CHANGED
|
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "getSunPosition", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function () {
|
|
8
|
+
get: function get() {
|
|
9
9
|
return _suncalc.getSunPosition;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "getSunDirection", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () {
|
|
14
|
+
get: function get() {
|
|
15
15
|
return _suncalc.getSunDirection;
|
|
16
16
|
}
|
|
17
17
|
});
|
package/dist/es5/suncalc.js
CHANGED
|
@@ -5,22 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getSunPosition = getSunPosition;
|
|
7
7
|
exports.getSunDirection = getSunDirection;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
var DEGREES_TO_RADIANS = Math.PI / 180;
|
|
9
|
+
var DAY_IN_MS = 1000 * 60 * 60 * 24;
|
|
10
|
+
var JD1970 = 2440588;
|
|
11
|
+
var JD2000 = 2451545;
|
|
12
|
+
var e = DEGREES_TO_RADIANS * 23.4397;
|
|
13
|
+
var M0 = 357.5291;
|
|
14
|
+
var M1 = 0.98560028;
|
|
15
|
+
var THETA0 = 280.147;
|
|
16
|
+
var THETA1 = 360.9856235;
|
|
17
17
|
|
|
18
18
|
function getSunPosition(timestamp, latitude, longitude) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
var longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
|
|
20
|
+
var phi = DEGREES_TO_RADIANS * latitude;
|
|
21
|
+
var d = toDays(timestamp);
|
|
22
|
+
var c = getSunCoords(d);
|
|
23
|
+
var H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
|
|
24
24
|
return {
|
|
25
25
|
azimuth: getAzimuth(H, phi, c.declination),
|
|
26
26
|
altitude: getAltitude(H, phi, c.declination)
|
|
@@ -28,11 +28,11 @@ function getSunPosition(timestamp, latitude, longitude) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function getSunDirection(timestamp, latitude, longitude) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
var _getSunPosition = getSunPosition(timestamp, latitude, longitude),
|
|
32
|
+
azimuth = _getSunPosition.azimuth,
|
|
33
|
+
altitude = _getSunPosition.altitude;
|
|
34
|
+
|
|
35
|
+
var azimuthN = azimuth + Math.PI;
|
|
36
36
|
return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -45,26 +45,26 @@ function toDays(timestamp) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function getRightAscension(eclipticLongitude, b) {
|
|
48
|
-
|
|
48
|
+
var lambda = eclipticLongitude;
|
|
49
49
|
return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function getDeclination(eclipticLongitude, b) {
|
|
53
|
-
|
|
53
|
+
var lambda = eclipticLongitude;
|
|
54
54
|
return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function getAzimuth(hourAngle, latitudeInRadians, declination) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
var H = hourAngle;
|
|
59
|
+
var phi = latitudeInRadians;
|
|
60
|
+
var delta = declination;
|
|
61
61
|
return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function getAltitude(hourAngle, latitudeInRadians, declination) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
var H = hourAngle;
|
|
66
|
+
var phi = latitudeInRadians;
|
|
67
|
+
var delta = declination;
|
|
68
68
|
return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -77,15 +77,15 @@ function getSolarMeanAnomaly(days) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function getEclipticLongitude(meanAnomaly) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
var M = meanAnomaly;
|
|
81
|
+
var C = DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));
|
|
82
|
+
var P = DEGREES_TO_RADIANS * 102.9372;
|
|
83
83
|
return M + C + P + Math.PI;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function getSunCoords(dates) {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
var M = getSolarMeanAnomaly(dates);
|
|
88
|
+
var L = getEclipticLongitude(M);
|
|
89
89
|
return {
|
|
90
90
|
declination: getDeclination(L, 0),
|
|
91
91
|
rightAscension: getRightAscension(L, 0)
|
package/dist/es5/suncalc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","azimuthN","sin","cos","toJulianDay","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":";;;;;;;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","azimuthN","sin","cos","toJulianDay","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":";;;;;;;AAAA,IAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,IAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,OAAf;AAGA,IAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,IAAMO,EAAE,GAAG,QAAX;AACA,IAAMC,EAAE,GAAG,UAAX;AAEA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,WAAf;;AAkBO,SAASC,cAAT,CACLC,SADK,EAELC,QAFK,EAGLC,SAHK,EAIc;AACnB,MAAMC,sBAAsB,GAAGf,kBAAkB,GAAG,CAACc,SAArD;AACA,MAAME,GAAG,GAAGhB,kBAAkB,GAAGa,QAAjC;AACA,MAAMI,CAAC,GAAGC,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math.PI / 180;\n\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n\n// This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\n\n// Refer https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Mean Anomaly\" section for explanation\nconst M0 = 357.5291; // Earth mean anomaly on start day\nconst M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun\n\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\n\n/**\n * A position in the sky defined by two angles\n * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).\n * The azimuth is the direction along the horizon, which we measure from south to west.\n * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).\n */\nexport type CelestialPosition = {\n azimuth: number;\n altitude: number;\n};\n\n/**\n * Calculate sun position\n * based on https://www.aa.quae.nl/en/reken/zonpositie.html\n * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\n */\nexport function getSunPosition(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): CelestialPosition {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): number[] {\n const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);\n // convert azimuth from 0 at south to be 0 at north\n const azimuthN = azimuth + Math.PI;\n\n // solar position to light direction\n return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];\n}\n\nfunction toJulianDay(timestamp) {\n return timestamp / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp) {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude, b) {\n const lambda = eclipticLongitude;\n return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));\n}\n\nfunction getDeclination(eclipticLongitude, b) {\n const lambda = eclipticLongitude;\n return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));\n}\n\nfunction getAzimuth(hourAngle, latitudeInRadians, declination) {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));\n}\n\nfunction getAltitude(hourAngle, latitudeInRadians, declination) {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));\n}\n\n// https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Observer section\"\nfunction getSiderealTime(dates, longitudeWestInRadians) {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days) {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly) {\n const M = meanAnomaly;\n // equation of center\n const C =\n DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));\n // perihelion of the Earth\n const P = DEGREES_TO_RADIANS * 102.9372;\n\n return M + C + P + Math.PI;\n}\n\nfunction getSunCoords(dates) {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],"file":"suncalc.js"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "3.6.0-alpha.
|
|
8
|
+
"version": "3.6.0-alpha.4",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"javascript",
|
|
11
11
|
"math",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.12.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "d2ce86da8b6f07f0af0236818138442f68e1d8e4"
|
|
32
32
|
}
|