@math.gl/sun 3.6.0-alpha.4 → 3.6.0-alpha.7
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/suncalc.js +3 -3
- package/dist/es5/suncalc.js.map +1 -1
- package/dist/esm/suncalc.js +3 -3
- package/dist/esm/suncalc.js.map +1 -1
- package/dist/suncalc.d.ts.map +1 -1
- package/dist/suncalc.js +7 -4
- package/package.json +2 -2
- package/src/suncalc.ts +20 -14
package/dist/es5/suncalc.js
CHANGED
|
@@ -32,12 +32,12 @@ function getSunDirection(timestamp, latitude, longitude) {
|
|
|
32
32
|
azimuth = _getSunPosition.azimuth,
|
|
33
33
|
altitude = _getSunPosition.altitude;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];
|
|
35
|
+
return [Math.sin(azimuth) * Math.cos(altitude), Math.cos(azimuth) * Math.cos(altitude), -Math.sin(altitude)];
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
function toJulianDay(timestamp) {
|
|
40
|
-
|
|
39
|
+
var ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
40
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function toDays(timestamp) {
|
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","
|
|
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,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,MAAM,CAACN,SAAD,CAAhB;AAEA,MAAMO,CAAC,GAAGC,YAAY,CAACH,CAAD,CAAtB;AAEA,MAAMI,CAAC,GAAGC,eAAe,CAACL,CAAD,EAAIF,sBAAJ,CAAf,GAA6CI,CAAC,CAACI,cAAzD;AAEA,SAAO;AACLC,IAAAA,OAAO,EAAEC,UAAU,CAACJ,CAAD,EAAIL,GAAJ,EAASG,CAAC,CAACO,WAAX,CADd;AAELC,IAAAA,QAAQ,EAAEC,WAAW,CAACP,CAAD,EAAIL,GAAJ,EAASG,CAAC,CAACO,WAAX;AAFhB,GAAP;AAID;;AAEM,SAASG,eAAT,CAC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,MAAM,GAAGC,MAAM,GAAGoC,KAAtB,CAAlB,GAAiD/B,sBAAxD;AACD;;AAED,SAASgC,mBAAT,CAA6BC,IAA7B,EAAmD;AACjD,SAAOhD,kBAAkB,IAAIO,EAAE,GAAGC,EAAE,GAAGwC,IAAd,CAAzB;AACD;;AAED,SAASC,oBAAT,CAA8BC,WAA9B,EAA2D;AACzD,MAAMC,CAAC,GAAGD,WAAV;AAEA,MAAME,CAAC,GACLpD,kBAAkB,IAAI,SAASC,IAAI,CAAC6B,GAAL,CAASqB,CAAT,CAAT,GAAuB,OAAOlD,IAAI,CAAC6B,GAAL,CAAS,IAAIqB,CAAb,CAA9B,GAAgD,SAASlD,IAAI,CAAC6B,GAAL,CAAS,IAAIqB,CAAb,CAA7D,CADpB;AAGA,MAAME,CAAC,GAAGrD,kBAAkB,GAAG,QAA/B;AAEA,SAAOmD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYpD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsB0B,KAAtB,EAGE;AACA,MAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,MAAMQ,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"}
|
package/dist/esm/suncalc.js
CHANGED
|
@@ -23,12 +23,12 @@ export function getSunDirection(timestamp, latitude, longitude) {
|
|
|
23
23
|
azimuth,
|
|
24
24
|
altitude
|
|
25
25
|
} = getSunPosition(timestamp, latitude, longitude);
|
|
26
|
-
|
|
27
|
-
return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];
|
|
26
|
+
return [Math.sin(azimuth) * Math.cos(altitude), Math.cos(azimuth) * Math.cos(altitude), -Math.sin(altitude)];
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
function toJulianDay(timestamp) {
|
|
31
|
-
|
|
30
|
+
const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
31
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function toDays(timestamp) {
|
package/dist/esm/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","
|
|
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;A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GAAGrD,kBAAkB,GAAG,QAA/B;AAEA,SAAOmD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYpD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsB0B,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"}
|
package/dist/suncalc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
package/dist/suncalc.js
CHANGED
|
@@ -29,13 +29,16 @@ export function getSunPosition(timestamp, latitude, longitude) {
|
|
|
29
29
|
}
|
|
30
30
|
export function getSunDirection(timestamp, latitude, longitude) {
|
|
31
31
|
const { azimuth, altitude } = getSunPosition(timestamp, latitude, longitude);
|
|
32
|
-
// convert azimuth from 0 at south to be 0 at north
|
|
33
|
-
const azimuthN = azimuth + Math.PI;
|
|
34
32
|
// solar position to light direction
|
|
35
|
-
return [
|
|
33
|
+
return [
|
|
34
|
+
Math.sin(azimuth) * Math.cos(altitude),
|
|
35
|
+
Math.cos(azimuth) * Math.cos(altitude),
|
|
36
|
+
-Math.sin(altitude)
|
|
37
|
+
];
|
|
36
38
|
}
|
|
37
39
|
function toJulianDay(timestamp) {
|
|
38
|
-
|
|
40
|
+
const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
41
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
39
42
|
}
|
|
40
43
|
function toDays(timestamp) {
|
|
41
44
|
return toJulianDay(timestamp) - JD2000;
|
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.7",
|
|
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": "166f7411d07d545e6a3f247b55b56f5cb8efccde"
|
|
32
32
|
}
|
package/src/suncalc.ts
CHANGED
|
@@ -56,39 +56,42 @@ export function getSunDirection(
|
|
|
56
56
|
longitude: number
|
|
57
57
|
): number[] {
|
|
58
58
|
const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);
|
|
59
|
-
// convert azimuth from 0 at south to be 0 at north
|
|
60
|
-
const azimuthN = azimuth + Math.PI;
|
|
61
59
|
|
|
62
60
|
// solar position to light direction
|
|
63
|
-
return [
|
|
61
|
+
return [
|
|
62
|
+
Math.sin(azimuth) * Math.cos(altitude),
|
|
63
|
+
Math.cos(azimuth) * Math.cos(altitude),
|
|
64
|
+
-Math.sin(altitude)
|
|
65
|
+
];
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
function toJulianDay(timestamp) {
|
|
67
|
-
|
|
68
|
+
function toJulianDay(timestamp: number | Date): number {
|
|
69
|
+
const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
70
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
function toDays(timestamp) {
|
|
73
|
+
function toDays(timestamp: number | Date): number {
|
|
71
74
|
return toJulianDay(timestamp) - JD2000;
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
function getRightAscension(eclipticLongitude, b) {
|
|
77
|
+
function getRightAscension(eclipticLongitude: number, b: number): number {
|
|
75
78
|
const lambda = eclipticLongitude;
|
|
76
79
|
return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
function getDeclination(eclipticLongitude, b) {
|
|
82
|
+
function getDeclination(eclipticLongitude: number, b: number): number {
|
|
80
83
|
const lambda = eclipticLongitude;
|
|
81
84
|
return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
function getAzimuth(hourAngle, latitudeInRadians, declination) {
|
|
87
|
+
function getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {
|
|
85
88
|
const H = hourAngle;
|
|
86
89
|
const phi = latitudeInRadians;
|
|
87
90
|
const delta = declination;
|
|
88
91
|
return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
function getAltitude(hourAngle, latitudeInRadians, declination) {
|
|
94
|
+
function getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {
|
|
92
95
|
const H = hourAngle;
|
|
93
96
|
const phi = latitudeInRadians;
|
|
94
97
|
const delta = declination;
|
|
@@ -97,15 +100,15 @@ function getAltitude(hourAngle, latitudeInRadians, declination) {
|
|
|
97
100
|
|
|
98
101
|
// https://www.aa.quae.nl/en/reken/zonpositie.html
|
|
99
102
|
// "The Observer section"
|
|
100
|
-
function getSiderealTime(dates, longitudeWestInRadians) {
|
|
103
|
+
function getSiderealTime(dates: number, longitudeWestInRadians: number): number {
|
|
101
104
|
return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
function getSolarMeanAnomaly(days) {
|
|
107
|
+
function getSolarMeanAnomaly(days: number): number {
|
|
105
108
|
return DEGREES_TO_RADIANS * (M0 + M1 * days);
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
function getEclipticLongitude(meanAnomaly) {
|
|
111
|
+
function getEclipticLongitude(meanAnomaly: number): number {
|
|
109
112
|
const M = meanAnomaly;
|
|
110
113
|
// equation of center
|
|
111
114
|
const C =
|
|
@@ -116,7 +119,10 @@ function getEclipticLongitude(meanAnomaly) {
|
|
|
116
119
|
return M + C + P + Math.PI;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
function getSunCoords(dates) {
|
|
122
|
+
function getSunCoords(dates: number): {
|
|
123
|
+
declination: number;
|
|
124
|
+
rightAscension: number;
|
|
125
|
+
} {
|
|
120
126
|
const M = getSolarMeanAnomaly(dates);
|
|
121
127
|
const L = getEclipticLongitude(M);
|
|
122
128
|
|