@math.gl/sun 4.0.0-beta.1 → 4.0.1

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/index.cjs CHANGED
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/index.ts
20
- var src_exports = {};
21
- __export(src_exports, {
19
+ // dist/index.js
20
+ var dist_exports = {};
21
+ __export(dist_exports, {
22
22
  getSunDirection: () => getSunDirection,
23
23
  getSunPosition: () => getSunPosition
24
24
  });
25
- module.exports = __toCommonJS(src_exports);
25
+ module.exports = __toCommonJS(dist_exports);
26
26
 
27
- // src/suncalc.ts
27
+ // dist/suncalc.js
28
28
  var DEGREES_TO_RADIANS = Math.PI / 180;
29
29
  var DAY_IN_MS = 1e3 * 60 * 60 * 24;
30
30
  var JD1970 = 2440588;
@@ -100,3 +100,4 @@ function getSunCoords(dates) {
100
100
  rightAscension: getRightAscension(L, 0)
101
101
  };
102
102
  }
103
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.js", "suncalc.js"],
4
+ "sourcesContent": ["export { getSunPosition, getSunDirection } from \"./suncalc.js\";\n", "const DEGREES_TO_RADIANS = Math.PI / 180;\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n// This angle \u03B5 [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397\u00B0\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\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\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0\u00B0 at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\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(timestamp, latitude, longitude) {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\nexport function getSunDirection(timestamp, latitude, longitude) {\n const { azimuth, altitude } = getSunPosition(timestamp, latitude, longitude);\n // solar position to light direction\n return [\n Math.sin(azimuth) * Math.cos(altitude),\n Math.cos(azimuth) * Math.cos(altitude),\n -Math.sin(altitude)\n ];\n}\nfunction toJulianDay(timestamp) {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\nfunction toDays(timestamp) {\n return toJulianDay(timestamp) - JD2000;\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}\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}\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}\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// 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}\nfunction getSolarMeanAnomaly(days) {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\nfunction getEclipticLongitude(meanAnomaly) {\n const M = meanAnomaly;\n // equation of center\n const C = 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 return M + C + P + Math.PI;\n}\nfunction getSunCoords(dates) {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,qBAAqB,KAAK,KAAK;AACrC,IAAM,YAAY,MAAO,KAAK,KAAK;AACnC,IAAM,SAAS;AACf,IAAM,SAAS;AAEf,IAAM,IAAI,qBAAqB;AAG/B,IAAM,KAAK;AACX,IAAM,KAAK;AACX,IAAM,SAAS;AACf,IAAM,SAAS;AAMR,SAAS,eAAe,WAAW,UAAU,WAAW;AAC3D,QAAM,yBAAyB,qBAAqB,CAAC;AACrD,QAAM,MAAM,qBAAqB;AACjC,QAAM,IAAI,OAAO,SAAS;AAC1B,QAAM,IAAI,aAAa,CAAC;AAExB,QAAM,IAAI,gBAAgB,GAAG,sBAAsB,IAAI,EAAE;AACzD,SAAO;AAAA,IACH,SAAS,WAAW,GAAG,KAAK,EAAE,WAAW;AAAA,IACzC,UAAU,YAAY,GAAG,KAAK,EAAE,WAAW;AAAA,EAC/C;AACJ;AACO,SAAS,gBAAgB,WAAW,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I,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,CAAC;AACpG;AAGA,SAAS,gBAAgB,OAAO,wBAAwB;AACpD,SAAO,sBAAsB,SAAS,SAAS,SAAS;AAC5D;AACA,SAAS,oBAAoB,MAAM;AAC/B,SAAO,sBAAsB,KAAK,KAAK;AAC3C;AACA,SAAS,qBAAqB,aAAa;AACvC,QAAM,IAAI;AAEV,QAAM,IAAI,sBAAsB,SAAS,KAAK,IAAI,CAAC,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,IAAI,OAAS,KAAK,IAAI,IAAI,CAAC;AAEvG,QAAM,IAAI,qBAAqB;AAC/B,SAAO,IAAI,IAAI,IAAI,KAAK;AAC5B;AACA,SAAS,aAAa,OAAO;AACzB,QAAM,IAAI,oBAAoB,KAAK;AACnC,QAAM,IAAI,qBAAqB,CAAC;AAChC,SAAO;AAAA,IACH,aAAa,eAAe,GAAG,CAAC;AAAA,IAChC,gBAAgB,kBAAkB,GAAG,CAAC;AAAA,EAC1C;AACJ;",
6
+ "names": []
7
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- export { getSunPosition, getSunDirection } from './suncalc';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export { getSunPosition, getSunDirection } from "./suncalc.js";
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { getSunPosition, getSunDirection } from "./suncalc.js";
2
- //# sourceMappingURL=index.js.map
package/dist/suncalc.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * The azimuth is the direction along the horizon, which we measure from south to west.
5
5
  * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
6
6
  */
7
- export declare type CelestialPosition = {
7
+ export type CelestialPosition = {
8
8
  azimuth: number;
9
9
  altitude: number;
10
10
  };
@@ -15,4 +15,3 @@ export declare type CelestialPosition = {
15
15
  */
16
16
  export declare function getSunPosition(timestamp: number | Date, latitude: number, longitude: number): CelestialPosition;
17
17
  export declare function getSunDirection(timestamp: number | Date, latitude: number, longitude: number): number[];
18
- //# sourceMappingURL=suncalc.d.ts.map
package/dist/suncalc.js CHANGED
@@ -1,85 +1,89 @@
1
1
  const DEGREES_TO_RADIANS = Math.PI / 180;
2
2
  const DAY_IN_MS = 1000 * 60 * 60 * 24;
3
- const JD1970 = 2440588;
4
- const JD2000 = 2451545;
5
- const e = DEGREES_TO_RADIANS * 23.4397;
6
- const M0 = 357.5291;
7
- const M1 = 0.98560028;
8
- const THETA0 = 280.147;
9
- const THETA1 = 360.9856235;
3
+ const JD1970 = 2440588; // Julian Day year 1970
4
+ const JD2000 = 2451545; // Julian Day year 2000
5
+ // This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°
6
+ const e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth
7
+ // Refer https://www.aa.quae.nl/en/reken/zonpositie.html
8
+ // "The Mean Anomaly" section for explanation
9
+ const M0 = 357.5291; // Earth mean anomaly on start day
10
+ const M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun
11
+ const THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000
12
+ const THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.
13
+ /**
14
+ * Calculate sun position
15
+ * based on https://www.aa.quae.nl/en/reken/zonpositie.html
16
+ * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js
17
+ */
10
18
  export function getSunPosition(timestamp, latitude, longitude) {
11
- const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
12
- const phi = DEGREES_TO_RADIANS * latitude;
13
- const d = toDays(timestamp);
14
- const c = getSunCoords(d);
15
- const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
16
- return {
17
- azimuth: getAzimuth(H, phi, c.declination),
18
- altitude: getAltitude(H, phi, c.declination)
19
- };
19
+ const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
20
+ const phi = DEGREES_TO_RADIANS * latitude;
21
+ const d = toDays(timestamp);
22
+ const c = getSunCoords(d);
23
+ // hour angle
24
+ const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
25
+ return {
26
+ azimuth: getAzimuth(H, phi, c.declination),
27
+ altitude: getAltitude(H, phi, c.declination)
28
+ };
20
29
  }
21
30
  export function getSunDirection(timestamp, latitude, longitude) {
22
- const {
23
- azimuth,
24
- altitude
25
- } = getSunPosition(timestamp, latitude, longitude);
26
- return [Math.sin(azimuth) * Math.cos(altitude), Math.cos(azimuth) * Math.cos(altitude), -Math.sin(altitude)];
31
+ const { azimuth, altitude } = getSunPosition(timestamp, latitude, longitude);
32
+ // solar position to light direction
33
+ return [
34
+ Math.sin(azimuth) * Math.cos(altitude),
35
+ Math.cos(azimuth) * Math.cos(altitude),
36
+ -Math.sin(altitude)
37
+ ];
27
38
  }
28
-
29
39
  function toJulianDay(timestamp) {
30
- const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
31
- return ts / DAY_IN_MS - 0.5 + JD1970;
40
+ const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
41
+ return ts / DAY_IN_MS - 0.5 + JD1970;
32
42
  }
33
-
34
43
  function toDays(timestamp) {
35
- return toJulianDay(timestamp) - JD2000;
44
+ return toJulianDay(timestamp) - JD2000;
36
45
  }
37
-
38
46
  function getRightAscension(eclipticLongitude, b) {
39
- const lambda = eclipticLongitude;
40
- return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
47
+ const lambda = eclipticLongitude;
48
+ return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
41
49
  }
42
-
43
50
  function getDeclination(eclipticLongitude, b) {
44
- const lambda = eclipticLongitude;
45
- return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
51
+ const lambda = eclipticLongitude;
52
+ return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
46
53
  }
47
-
48
54
  function getAzimuth(hourAngle, latitudeInRadians, declination) {
49
- const H = hourAngle;
50
- const phi = latitudeInRadians;
51
- const delta = declination;
52
- return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
55
+ const H = hourAngle;
56
+ const phi = latitudeInRadians;
57
+ const delta = declination;
58
+ return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
53
59
  }
54
-
55
60
  function getAltitude(hourAngle, latitudeInRadians, declination) {
56
- const H = hourAngle;
57
- const phi = latitudeInRadians;
58
- const delta = declination;
59
- return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));
61
+ const H = hourAngle;
62
+ const phi = latitudeInRadians;
63
+ const delta = declination;
64
+ return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));
60
65
  }
61
-
66
+ // https://www.aa.quae.nl/en/reken/zonpositie.html
67
+ // "The Observer section"
62
68
  function getSiderealTime(dates, longitudeWestInRadians) {
63
- return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
69
+ return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
64
70
  }
65
-
66
71
  function getSolarMeanAnomaly(days) {
67
- return DEGREES_TO_RADIANS * (M0 + M1 * days);
72
+ return DEGREES_TO_RADIANS * (M0 + M1 * days);
68
73
  }
69
-
70
74
  function getEclipticLongitude(meanAnomaly) {
71
- const M = meanAnomaly;
72
- const C = DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));
73
- const P = DEGREES_TO_RADIANS * 102.9372;
74
- return M + C + P + Math.PI;
75
+ const M = meanAnomaly;
76
+ // equation of center
77
+ const C = DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));
78
+ // perihelion of the Earth
79
+ const P = DEGREES_TO_RADIANS * 102.9372;
80
+ return M + C + P + Math.PI;
75
81
  }
76
-
77
82
  function getSunCoords(dates) {
78
- const M = getSolarMeanAnomaly(dates);
79
- const L = getEclipticLongitude(M);
80
- return {
81
- declination: getDeclination(L, 0),
82
- rightAscension: getRightAscension(L, 0)
83
- };
83
+ const M = getSolarMeanAnomaly(dates);
84
+ const L = getEclipticLongitude(M);
85
+ return {
86
+ declination: getDeclination(L, 0),
87
+ rightAscension: getRightAscension(L, 0)
88
+ };
84
89
  }
85
- //# sourceMappingURL=suncalc.js.map
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "version": "4.0.0-beta.1",
9
+ "version": "4.0.1",
10
10
  "keywords": [
11
11
  "javascript",
12
12
  "math",
@@ -24,17 +24,14 @@
24
24
  "module": "dist/index.js",
25
25
  "exports": {
26
26
  ".": {
27
+ "types": "./dist/index.d.ts",
27
28
  "import": "./dist/index.js",
28
- "require": "./dist/index.cjs",
29
- "types": "./dist/index.d.ts"
29
+ "require": "./dist/index.cjs"
30
30
  }
31
31
  },
32
32
  "files": [
33
33
  "dist",
34
34
  "src"
35
35
  ],
36
- "dependencies": {
37
- "@babel/runtime": "^7.12.0"
38
- },
39
- "gitHead": "5a2364216b6aadbece690e05b9b5b71753aee472"
36
+ "gitHead": "33f369ba3a259f79acc3fa8181190c9da8841648"
40
37
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,MAAM,WAAW,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["getSunPosition","getSunDirection"],"mappings":"SAAQA,c,EAAgBC,e","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"suncalc.d.ts","sourceRoot":"","sources":["../src/suncalc.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,iBAAiB,CAanB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CASV"}
@@ -1 +0,0 @@
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","sin","cos","toJulianDay","ts","getTime","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":"AAAA,MAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,MAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,MAAMC,MAAM,GAAG,OAAf;AACA,MAAMC,MAAM,GAAG,OAAf;AAGA,MAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,MAAMO,EAAE,GAAG,QAAX;AACA,MAAMC,EAAE,GAAG,UAAX;AAEA,MAAMC,MAAM,GAAG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AsB0B,KAAtB,EAGE;AACA,QAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,QAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACLzB,IAAAA,WAAW,EAAEe,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAEL/B,IAAAA,cAAc,EAAEY,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["const DEGREES_TO_RADIANS = 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\n // solar position to light direction\n return [\n Math.sin(azimuth) * Math.cos(altitude),\n Math.cos(azimuth) * Math.cos(altitude),\n -Math.sin(altitude)\n ];\n}\n\nfunction toJulianDay(timestamp: number | Date): number {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp: number | Date): number {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude: number, b: number): number {\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: number, b: number): number {\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: number, latitudeInRadians: number, declination: number): number {\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: number, latitudeInRadians: number, declination: number): number {\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: number, longitudeWestInRadians: number): number {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days: number): number {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly: number): number {\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: number): {\n declination: number;\n rightAscension: number;\n} {\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"}