@ac-kit/math-geodesy 0.1.0 → 0.2.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +47 -0
  3. package/dist/_ecef-height.d.ts +14 -12
  4. package/dist/_ecef-height.d.ts.map +1 -1
  5. package/dist/_ecef-height.js +115 -41
  6. package/dist/_ecef-height.js.map +1 -1
  7. package/dist/ellipsoid.d.ts +21 -0
  8. package/dist/ellipsoid.d.ts.map +1 -1
  9. package/dist/ellipsoid.js +57 -1
  10. package/dist/ellipsoid.js.map +1 -1
  11. package/dist/geodesic/_angle.d.ts +10 -15
  12. package/dist/geodesic/_angle.d.ts.map +1 -1
  13. package/dist/geodesic/_angle.js +54 -39
  14. package/dist/geodesic/_angle.js.map +1 -1
  15. package/dist/geodesic/_constants.d.ts.map +1 -1
  16. package/dist/geodesic/_constants.js +2 -1
  17. package/dist/geodesic/_constants.js.map +1 -1
  18. package/dist/geodesic/_inverse.d.ts.map +1 -1
  19. package/dist/geodesic/_inverse.js +34 -28
  20. package/dist/geodesic/_inverse.js.map +1 -1
  21. package/dist/geodesic/_line.d.ts +7 -8
  22. package/dist/geodesic/_line.d.ts.map +1 -1
  23. package/dist/geodesic/_line.js +28 -23
  24. package/dist/geodesic/_line.js.map +1 -1
  25. package/dist/geodesic/_series.js.map +1 -1
  26. package/dist/geodesic.d.ts +37 -9
  27. package/dist/geodesic.d.ts.map +1 -1
  28. package/dist/geodesic.js +173 -90
  29. package/dist/geodesic.js.map +1 -1
  30. package/dist/geodetic.d.ts +2 -1
  31. package/dist/geodetic.d.ts.map +1 -1
  32. package/dist/geodetic.js +42 -16
  33. package/dist/geodetic.js.map +1 -1
  34. package/dist/horizon.d.ts +63 -0
  35. package/dist/horizon.d.ts.map +1 -0
  36. package/dist/horizon.js +131 -0
  37. package/dist/horizon.js.map +1 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/local-frame.d.ts.map +1 -1
  43. package/dist/local-frame.js +40 -9
  44. package/dist/local-frame.js.map +1 -1
  45. package/dist/refraction.d.ts +80 -0
  46. package/dist/refraction.d.ts.map +1 -0
  47. package/dist/refraction.js +110 -0
  48. package/dist/refraction.js.map +1 -0
  49. package/package.json +12 -8
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The air along a near-horizontal sightline, for {@link refractionCurvature} and
3
+ * {@link refractionCoefficient}. Every field is optional; the defaults are the
4
+ * ISA atmosphere at sea level, seen in visible light.
5
+ */
6
+ export type RefractionConditions = {
7
+ /** The air temperature, °C; default `15`. */
8
+ readonly temperatureC?: number;
9
+ /** The station pressure (not reduced to sea level), hPa; default `1013.25`. */
10
+ readonly pressureHpa?: number;
11
+ /**
12
+ * The vertical temperature gradient `dT/dh`, kelvins per metre, positive when
13
+ * the air warms upwards (an inversion); default `−0.0065`, the ISA lapse
14
+ * rate. Refraction depends on it far more than on the temperature or the
15
+ * pressure: near the ground it ranges from about `−0.1` over sunlit land to
16
+ * `+0.1` over cold water.
17
+ */
18
+ readonly temperatureGradientKPerM?: number;
19
+ /** The vacuum wavelength, micrometres, in `[0.2, 2]`; default `0.55`. */
20
+ readonly wavelengthUm?: number;
21
+ };
22
+ /**
23
+ * Gauss's terrestrial refraction coefficient, `0.13`: the conventional value of
24
+ * geodetic levelling, for daytime sightlines well above the ground.
25
+ */
26
+ export declare const REFRACTION_COEFFICIENT_GAUSS = 0.13;
27
+ /**
28
+ * The curvature of a near-horizontal light ray, in 1/m, positive when the ray
29
+ * bends down towards the Earth: `κ = −(dn/dh) / n`.
30
+ *
31
+ * Dry air is taken as an ideal gas in hydrostatic balance, so the refractive
32
+ * index is `n − 1 = K(λ)·P/T` and its gradient `dn/dh = −K(λ)·P/T²·(g/R_d +
33
+ * dT/dh)`: the pressure falls by `g/R_d ≈ 0.0342 K/m` worth of density per
34
+ * metre and the temperature gradient adds its own. `K(λ)` comes from Birch and
35
+ * Downs' revision of Edlén's dispersion formula for standard air (Metrologia
36
+ * 31, 1994, 315–316). The ray is assumed near horizontal (its curvature scales
37
+ * with the cosine of its elevation). Water vapour is neglected: it changes
38
+ * visible refraction by well under 1 %.
39
+ *
40
+ * With the defaults the curvature is about `2.67e−8 /m`, a coefficient of
41
+ * `0.170` on the mean Earth radius. A temperature at or below absolute zero, a
42
+ * negative pressure, a wavelength outside `[0.2, 2]` µm or a value that is not
43
+ * finite gives `NaN`.
44
+ *
45
+ * @see {@link refractionCoefficient}
46
+ */
47
+ export declare function refractionCurvature(conditions?: RefractionConditions): number;
48
+ /**
49
+ * The terrestrial refraction coefficient `k = κR`: the ratio of the Earth's
50
+ * radius `radiusM` (default WGS 84's mean radius, 6 371 008.771 m) to the
51
+ * radius of a near-horizontal light ray in the given air (see
52
+ * {@link refractionCurvature}). `0` is no refraction, `0.13` to `0.17` a usual
53
+ * daytime value, `1` a ray as curved as the Earth (a flat-looking sea) and
54
+ * above `1` ducting; a strong lapse over hot ground makes it negative.
55
+ *
56
+ * Use the radius the coefficient will be applied with, such as
57
+ * `ellipsoidNormalSectionRadius` in the direction of the sightline: the
58
+ * coefficient is then that section's own. Hirt et al. (J. Geophys. Res. 115,
59
+ * 2010, D21102) give the usual approximation `503·P/T²·(0.0343 + dT/dh)`.
60
+ *
61
+ * A radius that is not finite and positive, or conditions
62
+ * {@link refractionCurvature} rejects, give `NaN`.
63
+ */
64
+ export declare function refractionCoefficient(conditions?: RefractionConditions, radiusM?: number): number;
65
+ /**
66
+ * The angle, degrees, by which refraction raises the apparent direction of a
67
+ * point at the straight-line distance `distanceM`, for a coefficient
68
+ * `refractionCoefficient` on a radius `radiusM`. The ray is the circular arc of
69
+ * curvature `k/R` through both points, and the angle is the one between its
70
+ * tangent at the observer and the chord: `asin(d·k / (2R))`, about `k` times
71
+ * half the central angle. Add it to the geometric elevation of the point (as an
72
+ * `affine3FromLocalFrame` east-north-up frame gives it) to get the apparent
73
+ * one; a negative coefficient lowers the point.
74
+ *
75
+ * No arc of that curvature spans the distance when `|d·k| > 2R`, which gives
76
+ * `NaN`, as does a negative or non-finite distance, a radius that is not finite
77
+ * and positive or a coefficient that is not finite.
78
+ */
79
+ export declare function refractionAngle(distanceM: number, radiusM: number, refractionCoefficient: number): number;
80
+ //# sourceMappingURL=refraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refraction.d.ts","sourceRoot":"","sources":["../src/refraction.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAC3C,yEAAyE;IACzE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,OAAO,CAAC;AAYjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAiC7E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACpC,UAAU,CAAC,EAAE,oBAAoB,EACjC,OAAO,GAAE,MAA6B,GACpC,MAAM,CAKR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,qBAAqB,EAAE,MAAM,GAC3B,MAAM,CAaR"}
@@ -0,0 +1,110 @@
1
+ import { RAD_TO_DEG } from "@ac-kit/math-scalar";
2
+ import { ELLIPSOID_WGS84, ellipsoidMeanRadius } from "./ellipsoid.js";
3
+ /**
4
+ * Gauss's terrestrial refraction coefficient, `0.13`: the conventional value of
5
+ * geodetic levelling, for daytime sightlines well above the ground.
6
+ */
7
+ export const REFRACTION_COEFFICIENT_GAUSS = 0.13;
8
+ const ZERO_CELSIUS_K_ = 273.15;
9
+ const STANDARD_GRAVITY_ = 9.80665;
10
+ /** The specific gas constant of dry air, J/(kg·K) (ISA, ICAO Doc 7488). */
11
+ const DRY_AIR_GAS_CONSTANT_ = 287.05287;
12
+ const STANDARD_AIR_TEMPERATURE_K_ = 288.15;
13
+ const STANDARD_AIR_PRESSURE_HPA_ = 1013.25;
14
+ const MINIMUM_WAVELENGTH_UM_ = 0.2;
15
+ const MAXIMUM_WAVELENGTH_UM_ = 2;
16
+ const WGS84_MEAN_RADIUS_M_ = ellipsoidMeanRadius(ELLIPSOID_WGS84);
17
+ /**
18
+ * The curvature of a near-horizontal light ray, in 1/m, positive when the ray
19
+ * bends down towards the Earth: `κ = −(dn/dh) / n`.
20
+ *
21
+ * Dry air is taken as an ideal gas in hydrostatic balance, so the refractive
22
+ * index is `n − 1 = K(λ)·P/T` and its gradient `dn/dh = −K(λ)·P/T²·(g/R_d +
23
+ * dT/dh)`: the pressure falls by `g/R_d ≈ 0.0342 K/m` worth of density per
24
+ * metre and the temperature gradient adds its own. `K(λ)` comes from Birch and
25
+ * Downs' revision of Edlén's dispersion formula for standard air (Metrologia
26
+ * 31, 1994, 315–316). The ray is assumed near horizontal (its curvature scales
27
+ * with the cosine of its elevation). Water vapour is neglected: it changes
28
+ * visible refraction by well under 1 %.
29
+ *
30
+ * With the defaults the curvature is about `2.67e−8 /m`, a coefficient of
31
+ * `0.170` on the mean Earth radius. A temperature at or below absolute zero, a
32
+ * negative pressure, a wavelength outside `[0.2, 2]` µm or a value that is not
33
+ * finite gives `NaN`.
34
+ *
35
+ * @see {@link refractionCoefficient}
36
+ */
37
+ export function refractionCurvature(conditions) {
38
+ const temperatureC = conditions?.temperatureC ?? 15;
39
+ const pressureHpa = conditions?.pressureHpa ?? STANDARD_AIR_PRESSURE_HPA_;
40
+ const gradient = conditions?.temperatureGradientKPerM ?? -0.0065;
41
+ const wavelengthUm = conditions?.wavelengthUm ?? 0.55;
42
+ const temperatureK = temperatureC + ZERO_CELSIUS_K_;
43
+ if (!(temperatureK > 0) ||
44
+ temperatureK === Number.POSITIVE_INFINITY ||
45
+ !(pressureHpa >= 0) ||
46
+ pressureHpa === Number.POSITIVE_INFINITY ||
47
+ !Number.isFinite(gradient) ||
48
+ !(wavelengthUm >= MINIMUM_WAVELENGTH_UM_ &&
49
+ wavelengthUm <= MAXIMUM_WAVELENGTH_UM_)) {
50
+ return Number.NaN;
51
+ }
52
+ const waveNumberSquared = 1 / (wavelengthUm * wavelengthUm);
53
+ const standardRefractivity = (8342.54 +
54
+ 2406147 / (130 - waveNumberSquared) +
55
+ 15998 / (38.9 - waveNumberSquared)) *
56
+ 1e-8;
57
+ const refractivityPerDensity = (standardRefractivity * STANDARD_AIR_TEMPERATURE_K_) /
58
+ STANDARD_AIR_PRESSURE_HPA_;
59
+ const refractivity = (refractivityPerDensity * pressureHpa) / temperatureK;
60
+ const indexGradient = (-refractivity / temperatureK) *
61
+ (STANDARD_GRAVITY_ / DRY_AIR_GAS_CONSTANT_ + gradient);
62
+ return -indexGradient / (1 + refractivity);
63
+ }
64
+ /**
65
+ * The terrestrial refraction coefficient `k = κR`: the ratio of the Earth's
66
+ * radius `radiusM` (default WGS 84's mean radius, 6 371 008.771 m) to the
67
+ * radius of a near-horizontal light ray in the given air (see
68
+ * {@link refractionCurvature}). `0` is no refraction, `0.13` to `0.17` a usual
69
+ * daytime value, `1` a ray as curved as the Earth (a flat-looking sea) and
70
+ * above `1` ducting; a strong lapse over hot ground makes it negative.
71
+ *
72
+ * Use the radius the coefficient will be applied with, such as
73
+ * `ellipsoidNormalSectionRadius` in the direction of the sightline: the
74
+ * coefficient is then that section's own. Hirt et al. (J. Geophys. Res. 115,
75
+ * 2010, D21102) give the usual approximation `503·P/T²·(0.0343 + dT/dh)`.
76
+ *
77
+ * A radius that is not finite and positive, or conditions
78
+ * {@link refractionCurvature} rejects, give `NaN`.
79
+ */
80
+ export function refractionCoefficient(conditions, radiusM = WGS84_MEAN_RADIUS_M_) {
81
+ if (!(radiusM > 0) || radiusM === Number.POSITIVE_INFINITY) {
82
+ return Number.NaN;
83
+ }
84
+ return refractionCurvature(conditions) * radiusM;
85
+ }
86
+ /**
87
+ * The angle, degrees, by which refraction raises the apparent direction of a
88
+ * point at the straight-line distance `distanceM`, for a coefficient
89
+ * `refractionCoefficient` on a radius `radiusM`. The ray is the circular arc of
90
+ * curvature `k/R` through both points, and the angle is the one between its
91
+ * tangent at the observer and the chord: `asin(d·k / (2R))`, about `k` times
92
+ * half the central angle. Add it to the geometric elevation of the point (as an
93
+ * `affine3FromLocalFrame` east-north-up frame gives it) to get the apparent
94
+ * one; a negative coefficient lowers the point.
95
+ *
96
+ * No arc of that curvature spans the distance when `|d·k| > 2R`, which gives
97
+ * `NaN`, as does a negative or non-finite distance, a radius that is not finite
98
+ * and positive or a coefficient that is not finite.
99
+ */
100
+ export function refractionAngle(distanceM, radiusM, refractionCoefficient) {
101
+ if (!(distanceM >= 0) ||
102
+ distanceM === Number.POSITIVE_INFINITY ||
103
+ !(radiusM > 0) ||
104
+ radiusM === Number.POSITIVE_INFINITY ||
105
+ !Number.isFinite(refractionCoefficient)) {
106
+ return Number.NaN;
107
+ }
108
+ return (Math.asin((distanceM * refractionCoefficient) / (2 * radiusM)) * RAD_TO_DEG);
109
+ }
110
+ //# sourceMappingURL=refraction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refraction.js","sourceRoot":"","sources":["../src/refraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAwBtE;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAEjD,MAAM,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AACH,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@ac-kit/math-geodesy",
3
- "version": "0.1.0",
4
- "description": "The Earth's reference ellipsoid: geodetic and ECEF coordinates, local frames and geodesics (direct, inverse and lines).",
3
+ "version": "0.2.0",
4
+ "description": "The Earth's reference ellipsoid: geodetic and ECEF coordinates, local frames, geodesics (direct, inverse and lines), curvature, horizon and terrestrial refraction.",
5
5
  "keywords": [
6
+ "curvature",
6
7
  "ecef",
7
8
  "ellipsoid",
8
9
  "geodesic",
9
10
  "geodesy",
11
+ "horizon",
12
+ "refraction",
10
13
  "wgs84"
11
14
  ],
12
15
  "homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/math-geodesy/",
@@ -47,17 +50,18 @@
47
50
  "prepack": "yarn build"
48
51
  },
49
52
  "dependencies": {
50
- "@ac-kit/core": "^0.12.0",
51
- "@ac-kit/math-geometry": "^0.3.0",
52
- "@ac-kit/math-linear": "^0.3.0",
53
- "@ac-kit/math-scalar": "^0.3.0",
53
+ "@ac-kit/core": "^0.14.0",
54
+ "@ac-kit/math-geometry": "^0.5.0",
55
+ "@ac-kit/math-linear": "^0.5.0",
56
+ "@ac-kit/math-scalar": "^0.5.0",
54
57
  "@types/web": "^0.0.367"
55
58
  },
56
59
  "devDependencies": {
57
- "@ac-kit/math-random": "0.4.0",
60
+ "@ac-kit/math-random": "0.4.2",
61
+ "@ac-kit/test-util": "0.5.1",
58
62
  "@ac-kit/tsconfig": "0.1.0",
59
63
  "@ac-kit/typedoc-config": "0.1.0",
60
- "@ac-kit/vitest-config": "0.2.0",
64
+ "@ac-kit/vitest-config": "0.3.0",
61
65
  "@types/node": "26.6.11",
62
66
  "@typescript/native": "typescript@7.0.2",
63
67
  "geographiclib-geodesic": "2.2.0",