@math.gl/sun 3.6.0 → 3.6.3

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "3.6.0",
8
+ "version": "3.6.3",
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": "8fd38abb4c44b89ccd8def81903b2f4d11fde7c4"
31
+ "gitHead": "0efab394df9babad7ed93027c1003f30528b2090"
32
32
  }
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export { getSunPosition, getSunDirection } from './suncalc';
package/dist/suncalc.js DELETED
@@ -1,89 +0,0 @@
1
- const DEGREES_TO_RADIANS = Math.PI / 180;
2
- const DAY_IN_MS = 1000 * 60 * 60 * 24;
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
- */
18
- export function getSunPosition(timestamp, latitude, longitude) {
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
- };
29
- }
30
- export function getSunDirection(timestamp, latitude, longitude) {
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
- ];
38
- }
39
- function toJulianDay(timestamp) {
40
- const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
41
- return ts / DAY_IN_MS - 0.5 + JD1970;
42
- }
43
- function toDays(timestamp) {
44
- return toJulianDay(timestamp) - JD2000;
45
- }
46
- function getRightAscension(eclipticLongitude, b) {
47
- const lambda = eclipticLongitude;
48
- return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
49
- }
50
- function getDeclination(eclipticLongitude, b) {
51
- const lambda = eclipticLongitude;
52
- return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
53
- }
54
- function getAzimuth(hourAngle, latitudeInRadians, declination) {
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));
59
- }
60
- function getAltitude(hourAngle, latitudeInRadians, declination) {
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));
65
- }
66
- // https://www.aa.quae.nl/en/reken/zonpositie.html
67
- // "The Observer section"
68
- function getSiderealTime(dates, longitudeWestInRadians) {
69
- return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
70
- }
71
- function getSolarMeanAnomaly(days) {
72
- return DEGREES_TO_RADIANS * (M0 + M1 * days);
73
- }
74
- function getEclipticLongitude(meanAnomaly) {
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;
81
- }
82
- function getSunCoords(dates) {
83
- const M = getSolarMeanAnomaly(dates);
84
- const L = getEclipticLongitude(M);
85
- return {
86
- declination: getDeclination(L, 0),
87
- rightAscension: getRightAscension(L, 0)
88
- };
89
- }