@johnmorrisdotca/chikyu-earth 0.52.0 → 0.54.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.
- package/CHANGELOG.md +19 -0
- package/README.md +4 -2
- package/dist/flat/colours.d.ts +55 -0
- package/dist/flat/colours.js +71 -0
- package/dist/flat/define.d.ts +3 -0
- package/dist/flat/define.js +6 -0
- package/dist/flat/element.d.ts +188 -0
- package/dist/flat/element.js +1541 -0
- package/dist/flat/facts.d.ts +172 -0
- package/dist/flat/facts.js +168 -0
- package/dist/flat/geometry.d.ts +160 -0
- package/dist/flat/geometry.js +156 -0
- package/dist/flat/index.d.ts +6 -0
- package/dist/flat/index.js +7 -0
- package/dist/flat/track-state.d.ts +174 -0
- package/dist/flat/track-state.js +223 -0
- package/dist/flat/words.d.ts +25 -0
- package/dist/flat/words.js +78 -0
- package/dist/passes/index.d.ts +2 -1
- package/dist/passes/index.js +1 -1
- package/dist/passes/passes.d.ts +34 -0
- package/dist/passes/passes.js +43 -2
- package/dist/realistic/element-base.d.ts +6 -0
- package/dist/realistic/element-base.js +15 -2
- package/dist/space/compass.d.ts +36 -0
- package/dist/space/compass.js +72 -0
- package/dist/space/element-base.d.ts +48 -1
- package/dist/space/element-base.js +95 -6
- package/dist/space/index.d.ts +2 -1
- package/dist/space/index.js +1 -0
- package/dist/space/north-up.d.ts +86 -0
- package/dist/space/north-up.js +104 -0
- package/dist/space/path-controls.d.ts +1 -1
- package/dist/space/path-controls.js +13 -2
- package/dist/space/path-ribbons.d.ts +4 -0
- package/dist/space/path-ribbons.js +8 -4
- package/dist/space/satellite-layer.d.ts +5 -0
- package/dist/space/satellite-layer.js +16 -4
- package/dist/space/scene.d.ts +23 -0
- package/dist/space/scene.js +18 -1
- package/package.json +13 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of an element set the facts read: the mean motion (revolutions a day), the eccentricity, the inclination and the right ascension of the ascending node (both degrees). Every `ElementSet` has them.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import type { FlatElements } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
7
|
+
*
|
|
8
|
+
* const gps: FlatElements = { MEAN_MOTION: 2.0056, ECCENTRICITY: 0.0102, INCLINATION: 55.1, RA_OF_ASC_NODE: 24.3 };
|
|
9
|
+
* console.log(gps.INCLINATION);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface FlatElements {
|
|
13
|
+
MEAN_MOTION: number;
|
|
14
|
+
ECCENTRICITY: number;
|
|
15
|
+
INCLINATION: number;
|
|
16
|
+
RA_OF_ASC_NODE: number;
|
|
17
|
+
/** Read only when present: the newest one is `newestEpochMs`. */
|
|
18
|
+
EPOCH?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What decides which satellites share an orbital plane.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import type { PlaneOptions } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
26
|
+
*
|
|
27
|
+
* const options: PlaneOptions = { gapDeg: 10, minShare: 0.25 };
|
|
28
|
+
* console.log(options.gapDeg);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface PlaneOptions {
|
|
32
|
+
/** Two satellites are in one plane when no gap in right ascension of more than this many degrees lies between them (10 by default: GPS, Galileo, GLONASS, Iridium and OneWeb come out as their real planes). */
|
|
33
|
+
gapDeg?: number;
|
|
34
|
+
/** A cluster is a plane when it holds at least this share of the biggest cluster's satellites (0.25 by default); a smaller one is a spare or a stray and is left in `other`. */
|
|
35
|
+
minShare?: number;
|
|
36
|
+
/** ...and at least this many satellites (2 by default). */
|
|
37
|
+
minSize?: number;
|
|
38
|
+
/** Satellites at or under this inclination, in degrees, are left out of the planes (5 by default): on an orbit that is nearly round the equator the node is not defined, and a geostationary belt has no planes. */
|
|
39
|
+
minInclination?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One orbital plane: the satellites whose orbits cross the equator, going north, within a narrow stretch of longitude.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import type { Plane } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
47
|
+
*
|
|
48
|
+
* const describe = (plane: Plane): string => `Plane ${plane.id}: ${plane.count} satellites at ${plane.raanDeg.toFixed(0)} degrees`;
|
|
49
|
+
* console.log(typeof describe);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export interface Plane {
|
|
53
|
+
/** The letter: `A` for the first plane going east from 0 degrees of right ascension, then `B`, `C`; after `Z`, `AA`. */
|
|
54
|
+
id: string;
|
|
55
|
+
/** Its place in the list of planes, from 0. */
|
|
56
|
+
index: number;
|
|
57
|
+
count: number;
|
|
58
|
+
/** The middle of the plane's right ascension of the ascending node, degrees from 0 up to 360. */
|
|
59
|
+
raanDeg: number;
|
|
60
|
+
/** How wide the plane is in right ascension, degrees (0 for one satellite). */
|
|
61
|
+
spanDeg: number;
|
|
62
|
+
/** Which satellites are in it: indices into the list the planes were made from. */
|
|
63
|
+
members: readonly number[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The planes of a group, and the satellites that are in none.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import type { PlaneClusters } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
71
|
+
*
|
|
72
|
+
* const count = (clusters: PlaneClusters): number => clusters.planes.length;
|
|
73
|
+
* console.log(typeof count);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export interface PlaneClusters {
|
|
77
|
+
/** The planes, lettered in order of right ascension. */
|
|
78
|
+
planes: readonly Plane[];
|
|
79
|
+
/** Satellites that belong to no plane: too few to make a plane, or on an orbit with no node (see `minInclination`). Indices into the list. */
|
|
80
|
+
other: readonly number[];
|
|
81
|
+
/** For each satellite of the list, the `index` of its plane, or -1 when it is in `other`. */
|
|
82
|
+
planeOf: Int16Array;
|
|
83
|
+
/** True when the right ascension really does fall into two or more planes. False for one blob (Starlink's 5,000 satellites are spread through every longitude: no plane to show) and for a single plane. */
|
|
84
|
+
clustered: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The letter of the plane at `index`: `A` to `Z`, then `AA`, `AB`.
|
|
88
|
+
*
|
|
89
|
+
* @param index - From 0.
|
|
90
|
+
* @returns The letters.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { planeLetter } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
95
|
+
*
|
|
96
|
+
* console.log(planeLetter(0), planeLetter(25), planeLetter(26));
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function planeLetter(index: number): string;
|
|
100
|
+
/**
|
|
101
|
+
* Cluster satellites into orbital planes by the right ascension of their ascending node: sort the nodes round the circle, cut it at every gap wider than `gapDeg`, and keep the clusters big enough to be a plane.
|
|
102
|
+
* Navigation constellations come out as their real planes (GPS 6, Galileo 3, GLONASS 3), Iridium as 6, OneWeb as 12. A group spread evenly through every longitude (Starlink) is one cluster and `clustered` is false.
|
|
103
|
+
*
|
|
104
|
+
* @param elements - Anything with `INCLINATION` and `RA_OF_ASC_NODE`, one for each satellite.
|
|
105
|
+
* @param options - See `PlaneOptions`.
|
|
106
|
+
* @returns The planes, lettered `A`, `B`, `C` going east, the satellites that are in none, and which plane each satellite is in.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { clusterPlanes } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
111
|
+
*
|
|
112
|
+
* const node = (RA_OF_ASC_NODE: number) => ({ MEAN_MOTION: 2, ECCENTRICITY: 0, INCLINATION: 55, RA_OF_ASC_NODE });
|
|
113
|
+
* const { planes, clustered } = clusterPlanes([node(10), node(12), node(130), node(133), node(250), node(252)]);
|
|
114
|
+
* console.log(planes.map((plane) => `${plane.id}:${plane.count}`).join(" "), clustered);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function clusterPlanes(elements: readonly Pick<FlatElements, "INCLINATION" | "RA_OF_ASC_NODE">[], options?: PlaneOptions): PlaneClusters;
|
|
118
|
+
/**
|
|
119
|
+
* What `groupFacts` says about a group.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import type { GroupFacts } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
124
|
+
*
|
|
125
|
+
* const line = (facts: GroupFacts): string => `${facts.count} satellites, ${facts.meanAltitudeKm.toFixed(0)} km up`;
|
|
126
|
+
* console.log(typeof line);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export interface GroupFacts {
|
|
130
|
+
count: number;
|
|
131
|
+
/** The mean height of the satellites' orbits (half the longest width of each ellipse less the mean Earth radius of 6,371 km), kilometres. */
|
|
132
|
+
meanAltitudeKm: number;
|
|
133
|
+
/** The lowest point of any orbit of the group, kilometres above 6,371 km. */
|
|
134
|
+
minAltitudeKm: number;
|
|
135
|
+
/** The highest point of any orbit of the group, kilometres. */
|
|
136
|
+
maxAltitudeKm: number;
|
|
137
|
+
/** The mean inclination, degrees, and the lowest and highest. */
|
|
138
|
+
meanInclinationDeg: number;
|
|
139
|
+
minInclinationDeg: number;
|
|
140
|
+
maxInclinationDeg: number;
|
|
141
|
+
/** The mean time to go round once, minutes. */
|
|
142
|
+
periodMinutes: number;
|
|
143
|
+
/** The mean speed against the stars, kilometres a second (a circle at each orbit's own size). */
|
|
144
|
+
speedKmS: number;
|
|
145
|
+
/** How many planes the right ascension falls into (`planes.length`). With `clustered` false a 1 here means only that nothing separates them. */
|
|
146
|
+
planeCount: number;
|
|
147
|
+
planes: readonly Plane[];
|
|
148
|
+
/** Satellites that belong to no plane. */
|
|
149
|
+
otherCount: number;
|
|
150
|
+
/** See `PlaneClusters.clustered`: false for a group with no planes to show (Starlink) and for one plane. */
|
|
151
|
+
clustered: boolean;
|
|
152
|
+
/** The newest element set's moment in milliseconds since the Unix epoch, or 0 when no set has an `EPOCH`. */
|
|
153
|
+
newestEpochMs: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The facts of a group from its element sets: the count, mean height and the lowest and highest points, inclination, period, speed and the orbital planes. A set that is not an orbit (no mean motion) is left out, and the planes' `members` count the sets that are kept.
|
|
157
|
+
* Heights are above the mean Earth radius of 6,371 km, as `orbitShape` and the satellites' own readout give them. An empty group has every number 0.
|
|
158
|
+
*
|
|
159
|
+
* @param elements - The group's element sets.
|
|
160
|
+
* @param options - How the planes are found, see `PlaneOptions`.
|
|
161
|
+
* @returns The facts.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* import { groupFacts } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
166
|
+
*
|
|
167
|
+
* const gps = (RA_OF_ASC_NODE: number) => ({ MEAN_MOTION: 2.00563, ECCENTRICITY: 0.0102, INCLINATION: 55.1, RA_OF_ASC_NODE });
|
|
168
|
+
* const facts = groupFacts([gps(24), gps(26), gps(84), gps(86), gps(144), gps(146)]);
|
|
169
|
+
* console.log(facts.count, Math.round(facts.meanAltitudeKm), Math.round(facts.periodMinutes), facts.planeCount);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function groupFacts(elements: readonly FlatElements[], options?: PlaneOptions): GroupFacts;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// The facts of a group of satellites, worked out from their orbital elements alone: how many, how high, how steep, how quick, and which orbital planes they share. Pure: no DOM, no clock and
|
|
2
|
+
// no dependency (not even satellite.js), so a build step or a server can write "GPS: 6 planes, 20,200 km, 55 degrees" into a page before any script runs.
|
|
3
|
+
import { orbitShape } from "../catalogue/orbit.js";
|
|
4
|
+
const MU = 398_600.4418;
|
|
5
|
+
/**
|
|
6
|
+
* The letter of the plane at `index`: `A` to `Z`, then `AA`, `AB`.
|
|
7
|
+
*
|
|
8
|
+
* @param index - From 0.
|
|
9
|
+
* @returns The letters.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { planeLetter } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
14
|
+
*
|
|
15
|
+
* console.log(planeLetter(0), planeLetter(25), planeLetter(26));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function planeLetter(index) {
|
|
19
|
+
const n = Math.max(0, Math.floor(index));
|
|
20
|
+
return n < 26 ? String.fromCharCode(65 + n) : `${String.fromCharCode(65 + (Math.floor(n / 26) - 1) % 26)}${String.fromCharCode(65 + (n % 26))}`;
|
|
21
|
+
}
|
|
22
|
+
const wrap360 = (degrees) => ((degrees % 360) + 360) % 360;
|
|
23
|
+
/**
|
|
24
|
+
* Cluster satellites into orbital planes by the right ascension of their ascending node: sort the nodes round the circle, cut it at every gap wider than `gapDeg`, and keep the clusters big enough to be a plane.
|
|
25
|
+
* Navigation constellations come out as their real planes (GPS 6, Galileo 3, GLONASS 3), Iridium as 6, OneWeb as 12. A group spread evenly through every longitude (Starlink) is one cluster and `clustered` is false.
|
|
26
|
+
*
|
|
27
|
+
* @param elements - Anything with `INCLINATION` and `RA_OF_ASC_NODE`, one for each satellite.
|
|
28
|
+
* @param options - See `PlaneOptions`.
|
|
29
|
+
* @returns The planes, lettered `A`, `B`, `C` going east, the satellites that are in none, and which plane each satellite is in.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { clusterPlanes } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
34
|
+
*
|
|
35
|
+
* const node = (RA_OF_ASC_NODE: number) => ({ MEAN_MOTION: 2, ECCENTRICITY: 0, INCLINATION: 55, RA_OF_ASC_NODE });
|
|
36
|
+
* const { planes, clustered } = clusterPlanes([node(10), node(12), node(130), node(133), node(250), node(252)]);
|
|
37
|
+
* console.log(planes.map((plane) => `${plane.id}:${plane.count}`).join(" "), clustered);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function clusterPlanes(elements, options = {}) {
|
|
41
|
+
const gap = options.gapDeg ?? 10;
|
|
42
|
+
const share = options.minShare ?? 0.25;
|
|
43
|
+
const least = options.minSize ?? 2;
|
|
44
|
+
const flat = options.minInclination ?? 5;
|
|
45
|
+
const n = elements.length;
|
|
46
|
+
const planeOf = new Int16Array(n).fill(-1);
|
|
47
|
+
const usable = [];
|
|
48
|
+
for (let i = 0; i < n; i += 1) {
|
|
49
|
+
const e = elements[i];
|
|
50
|
+
if (Number.isFinite(e.RA_OF_ASC_NODE) && Number.isFinite(e.INCLINATION) && e.INCLINATION > flat)
|
|
51
|
+
usable.push(i);
|
|
52
|
+
}
|
|
53
|
+
const raan = (i) => wrap360(elements[i].RA_OF_ASC_NODE);
|
|
54
|
+
usable.sort((a, b) => raan(a) - raan(b));
|
|
55
|
+
const m = usable.length;
|
|
56
|
+
if (m === 0)
|
|
57
|
+
return { planes: [], other: Array.from({ length: n }, (_, i) => i), planeOf, clustered: false };
|
|
58
|
+
// start the walk just after the widest gap, so no cluster is cut by the point where 360 turns into 0
|
|
59
|
+
let start = 0;
|
|
60
|
+
let widest = -1;
|
|
61
|
+
for (let k = 0; k < m; k += 1) {
|
|
62
|
+
const here = raan(usable[k]);
|
|
63
|
+
const next = k + 1 < m ? raan(usable[k + 1]) : raan(usable[0]) + 360;
|
|
64
|
+
if (next - here > widest) {
|
|
65
|
+
widest = next - here;
|
|
66
|
+
start = (k + 1) % m;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const unrolled = (k) => {
|
|
70
|
+
const at = (start + k) % m;
|
|
71
|
+
return raan(usable[at]) + (at < start ? 360 : 0);
|
|
72
|
+
};
|
|
73
|
+
const clusters = [];
|
|
74
|
+
let current = { members: [usable[start]], first: unrolled(0), last: unrolled(0) };
|
|
75
|
+
for (let k = 1; k < m; k += 1) {
|
|
76
|
+
const value = unrolled(k);
|
|
77
|
+
const index = usable[(start + k) % m];
|
|
78
|
+
if (value - current.last > gap) {
|
|
79
|
+
clusters.push(current);
|
|
80
|
+
current = { members: [index], first: value, last: value };
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
current.members.push(index);
|
|
84
|
+
current.last = value;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
clusters.push(current);
|
|
88
|
+
const biggest = Math.max(...clusters.map((one) => one.members.length));
|
|
89
|
+
const major = clusters.filter((one) => one.members.length >= least && one.members.length >= share * biggest);
|
|
90
|
+
const planes = major
|
|
91
|
+
.map((one) => ({ members: one.members, raanDeg: wrap360((one.first + one.last) / 2), spanDeg: one.last - one.first }))
|
|
92
|
+
.sort((a, b) => a.raanDeg - b.raanDeg)
|
|
93
|
+
.map((one, index) => ({ id: planeLetter(index), index, count: one.members.length, raanDeg: one.raanDeg, spanDeg: one.spanDeg, members: one.members }));
|
|
94
|
+
for (const plane of planes)
|
|
95
|
+
for (const member of plane.members)
|
|
96
|
+
planeOf[member] = plane.index;
|
|
97
|
+
const other = [];
|
|
98
|
+
for (let i = 0; i < n; i += 1)
|
|
99
|
+
if (planeOf[i] === -1)
|
|
100
|
+
other.push(i);
|
|
101
|
+
return { planes, other, planeOf, clustered: planes.length >= 2 };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The facts of a group from its element sets: the count, mean height and the lowest and highest points, inclination, period, speed and the orbital planes. A set that is not an orbit (no mean motion) is left out, and the planes' `members` count the sets that are kept.
|
|
105
|
+
* Heights are above the mean Earth radius of 6,371 km, as `orbitShape` and the satellites' own readout give them. An empty group has every number 0.
|
|
106
|
+
*
|
|
107
|
+
* @param elements - The group's element sets.
|
|
108
|
+
* @param options - How the planes are found, see `PlaneOptions`.
|
|
109
|
+
* @returns The facts.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { groupFacts } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
114
|
+
*
|
|
115
|
+
* const gps = (RA_OF_ASC_NODE: number) => ({ MEAN_MOTION: 2.00563, ECCENTRICITY: 0.0102, INCLINATION: 55.1, RA_OF_ASC_NODE });
|
|
116
|
+
* const facts = groupFacts([gps(24), gps(26), gps(84), gps(86), gps(144), gps(146)]);
|
|
117
|
+
* console.log(facts.count, Math.round(facts.meanAltitudeKm), Math.round(facts.periodMinutes), facts.planeCount);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function groupFacts(elements, options = {}) {
|
|
121
|
+
const orbits = elements.filter((one) => orbitShape(one.MEAN_MOTION, one.ECCENTRICITY) !== null);
|
|
122
|
+
const count = orbits.length;
|
|
123
|
+
if (count === 0) {
|
|
124
|
+
return { count: 0, meanAltitudeKm: 0, minAltitudeKm: 0, maxAltitudeKm: 0, meanInclinationDeg: 0, minInclinationDeg: 0, maxInclinationDeg: 0, periodMinutes: 0, speedKmS: 0, planeCount: 0, planes: [], otherCount: 0, clustered: false, newestEpochMs: 0 };
|
|
125
|
+
}
|
|
126
|
+
let altitude = 0;
|
|
127
|
+
let low = Infinity;
|
|
128
|
+
let high = -Infinity;
|
|
129
|
+
let inclination = 0;
|
|
130
|
+
let lowInclination = Infinity;
|
|
131
|
+
let highInclination = -Infinity;
|
|
132
|
+
let period = 0;
|
|
133
|
+
let speed = 0;
|
|
134
|
+
let newest = 0;
|
|
135
|
+
for (const one of orbits) {
|
|
136
|
+
const shape = orbitShape(one.MEAN_MOTION, one.ECCENTRICITY);
|
|
137
|
+
altitude += shape.semiMajorKm - 6371;
|
|
138
|
+
low = Math.min(low, shape.perigeeKm);
|
|
139
|
+
high = Math.max(high, shape.apogeeKm);
|
|
140
|
+
inclination += one.INCLINATION;
|
|
141
|
+
lowInclination = Math.min(lowInclination, one.INCLINATION);
|
|
142
|
+
highInclination = Math.max(highInclination, one.INCLINATION);
|
|
143
|
+
period += shape.periodMinutes;
|
|
144
|
+
speed += Math.sqrt(MU / shape.semiMajorKm);
|
|
145
|
+
if (one.EPOCH) {
|
|
146
|
+
const epoch = Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(one.EPOCH) ? one.EPOCH : `${one.EPOCH}Z`);
|
|
147
|
+
if (Number.isFinite(epoch) && epoch > newest)
|
|
148
|
+
newest = epoch;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const clusters = clusterPlanes(orbits, options);
|
|
152
|
+
return {
|
|
153
|
+
count,
|
|
154
|
+
meanAltitudeKm: altitude / count,
|
|
155
|
+
minAltitudeKm: low,
|
|
156
|
+
maxAltitudeKm: high,
|
|
157
|
+
meanInclinationDeg: inclination / count,
|
|
158
|
+
minInclinationDeg: lowInclination,
|
|
159
|
+
maxInclinationDeg: highInclination,
|
|
160
|
+
periodMinutes: period / count,
|
|
161
|
+
speedKmS: speed / count,
|
|
162
|
+
planeCount: clusters.planes.length,
|
|
163
|
+
planes: clusters.planes,
|
|
164
|
+
otherCount: clusters.other.length,
|
|
165
|
+
clustered: clusters.clustered,
|
|
166
|
+
newestEpochMs: newest,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Longitude brought into -180 up to (not including) 180.
|
|
3
|
+
*
|
|
4
|
+
* @param lon - Degrees.
|
|
5
|
+
* @returns The same direction, wrapped.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { wrapLongitude } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
10
|
+
*
|
|
11
|
+
* console.log(wrapLongitude(190), wrapLongitude(-181), wrapLongitude(180));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const wrapLongitude: (lon: number) => number;
|
|
15
|
+
/**
|
|
16
|
+
* How the flat map sits in its box: the box's size in pixels, the longitude and latitude under its middle, and the zoom (1 shows the whole world, up to 8).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { FlatView } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
21
|
+
*
|
|
22
|
+
* const view: FlatView = { width: 800, height: 400, centerLon: 0, centerLat: 0, zoom: 1 };
|
|
23
|
+
* console.log(view.zoom);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface FlatView {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
centerLon: number;
|
|
30
|
+
centerLat: number;
|
|
31
|
+
zoom: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The furthest the map zooms in: 8 times the whole-world view.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { MAX_ZOOM } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
39
|
+
*
|
|
40
|
+
* console.log(MAX_ZOOM);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const MAX_ZOOM = 8;
|
|
44
|
+
/**
|
|
45
|
+
* Pixels for one degree: the world fills the box, as wide as it is, or as tall as it is when the box is taller than 2 to 1, so a phone's box is filled and the map wraps round its sides.
|
|
46
|
+
*
|
|
47
|
+
* @param view - The view.
|
|
48
|
+
* @returns Pixels a degree, of longitude or latitude (they are the same on this map).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { pixelsPerDegree } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
53
|
+
*
|
|
54
|
+
* console.log(pixelsPerDegree({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }), pixelsPerDegree({ width: 390, height: 520, centerLon: 0, centerLat: 0, zoom: 1 }).toFixed(2));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const pixelsPerDegree: (view: FlatView) => number;
|
|
58
|
+
/**
|
|
59
|
+
* Where a longitude and latitude fall in the box, in pixels from its top left. The longitude is taken the short way round from the middle, so a place wraps cleanly at the map's edges.
|
|
60
|
+
*
|
|
61
|
+
* @param view - The view.
|
|
62
|
+
* @param lon - Degrees east.
|
|
63
|
+
* @param lat - Degrees north.
|
|
64
|
+
* @returns `x` and `y` in pixels.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { projectFlat } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
69
|
+
*
|
|
70
|
+
* const view = { width: 720, height: 360, centerLon: 155, centerLat: 0, zoom: 1 };
|
|
71
|
+
* console.log(projectFlat(view, 139.7, 35.7), projectFlat(view, -170, 0));
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function projectFlat(view: FlatView, lon: number, lat: number): {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The longitude and latitude at a point of the box: the opposite of `projectFlat`. The latitude is not limited to the map (a point above the top gives more than 90).
|
|
80
|
+
*
|
|
81
|
+
* @param view - The view.
|
|
82
|
+
* @param x - Pixels from the left.
|
|
83
|
+
* @param y - Pixels from the top.
|
|
84
|
+
* @returns `lon` in -180 up to 180 and `lat`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { unprojectFlat } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
89
|
+
*
|
|
90
|
+
* console.log(unprojectFlat({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 360, 180));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function unprojectFlat(view: FlatView, x: number, y: number): {
|
|
94
|
+
lon: number;
|
|
95
|
+
lat: number;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The view kept inside what the map can show: the zoom between 1 and 8, the longitude wrapped, and the middle's latitude so that the poles are never further in than the box's edges.
|
|
99
|
+
*
|
|
100
|
+
* @param view - The view asked for.
|
|
101
|
+
* @returns The view to use.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { clampView } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
106
|
+
*
|
|
107
|
+
* console.log(clampView({ width: 720, height: 360, centerLon: 200, centerLat: 40, zoom: 1 }));
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function clampView(view: FlatView): FlatView;
|
|
111
|
+
/**
|
|
112
|
+
* Zoom by a factor about a point of the box, so the place under that point stays under it.
|
|
113
|
+
*
|
|
114
|
+
* @param view - The view.
|
|
115
|
+
* @param factor - Above 1 zooms in.
|
|
116
|
+
* @param x - Pixels from the left; the middle when left out.
|
|
117
|
+
* @param y - Pixels from the top; the middle when left out.
|
|
118
|
+
* @returns The new view, clamped.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { zoomAbout } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
123
|
+
*
|
|
124
|
+
* console.log(zoomAbout({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 2, 540, 90).zoom);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function zoomAbout(view: FlatView, factor: number, x?: number, y?: number): FlatView;
|
|
128
|
+
/**
|
|
129
|
+
* Where a satellite is on the Earth, from its place in the satellites' axes (`createSatellites`: Earth radii from the Earth's centre, x to the vernal equinox, y north, z the other way from TEME's y) and how far the Earth has turned
|
|
130
|
+
* (`greenwichSidereal`). The latitude is geodetic (the Earth's flattening is applied to the geocentric one), the height is above 6,371 km.
|
|
131
|
+
*
|
|
132
|
+
* @param x - Earth radii.
|
|
133
|
+
* @param y - Earth radii, north.
|
|
134
|
+
* @param z - Earth radii.
|
|
135
|
+
* @param siderealDeg - Greenwich mean sidereal time in degrees.
|
|
136
|
+
* @returns Longitude in -180 up to 180, latitude and height in kilometres.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { groundPoint } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
141
|
+
*
|
|
142
|
+
* console.log(groundPoint(1.1, 0, 0, 0));
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function groundPoint(x: number, y: number, z: number, siderealDeg: number): {
|
|
146
|
+
lon: number;
|
|
147
|
+
lat: number;
|
|
148
|
+
altitudeKm: number;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* (1 - f)^2 for the Earth's flattening f = 1/298.257: the factor between the tangent of the geocentric and of the geodetic latitude.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { FLATTENED } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
156
|
+
*
|
|
157
|
+
* console.log(FLATTENED);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare const FLATTENED = 0.99330562;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// The flat map's own geometry: an equirectangular (plate carree) map that wraps round the world, with the satellites' inertial places turned into longitude and latitude. Pure: numbers in, numbers out.
|
|
2
|
+
const RAD = Math.PI / 180;
|
|
3
|
+
/**
|
|
4
|
+
* Longitude brought into -180 up to (not including) 180.
|
|
5
|
+
*
|
|
6
|
+
* @param lon - Degrees.
|
|
7
|
+
* @returns The same direction, wrapped.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { wrapLongitude } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
12
|
+
*
|
|
13
|
+
* console.log(wrapLongitude(190), wrapLongitude(-181), wrapLongitude(180));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const wrapLongitude = (lon) => ((((lon + 180) % 360) + 360) % 360) - 180;
|
|
17
|
+
/**
|
|
18
|
+
* The furthest the map zooms in: 8 times the whole-world view.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { MAX_ZOOM } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
23
|
+
*
|
|
24
|
+
* console.log(MAX_ZOOM);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const MAX_ZOOM = 8;
|
|
28
|
+
/**
|
|
29
|
+
* Pixels for one degree: the world fills the box, as wide as it is, or as tall as it is when the box is taller than 2 to 1, so a phone's box is filled and the map wraps round its sides.
|
|
30
|
+
*
|
|
31
|
+
* @param view - The view.
|
|
32
|
+
* @returns Pixels a degree, of longitude or latitude (they are the same on this map).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { pixelsPerDegree } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
37
|
+
*
|
|
38
|
+
* console.log(pixelsPerDegree({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }), pixelsPerDegree({ width: 390, height: 520, centerLon: 0, centerLat: 0, zoom: 1 }).toFixed(2));
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const pixelsPerDegree = (view) => Math.max(view.width / 360, view.height / 180) * view.zoom;
|
|
42
|
+
/**
|
|
43
|
+
* Where a longitude and latitude fall in the box, in pixels from its top left. The longitude is taken the short way round from the middle, so a place wraps cleanly at the map's edges.
|
|
44
|
+
*
|
|
45
|
+
* @param view - The view.
|
|
46
|
+
* @param lon - Degrees east.
|
|
47
|
+
* @param lat - Degrees north.
|
|
48
|
+
* @returns `x` and `y` in pixels.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { projectFlat } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
53
|
+
*
|
|
54
|
+
* const view = { width: 720, height: 360, centerLon: 155, centerLat: 0, zoom: 1 };
|
|
55
|
+
* console.log(projectFlat(view, 139.7, 35.7), projectFlat(view, -170, 0));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function projectFlat(view, lon, lat) {
|
|
59
|
+
const k = pixelsPerDegree(view);
|
|
60
|
+
return { x: view.width / 2 + wrapLongitude(lon - view.centerLon) * k, y: view.height / 2 - (lat - view.centerLat) * k };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The longitude and latitude at a point of the box: the opposite of `projectFlat`. The latitude is not limited to the map (a point above the top gives more than 90).
|
|
64
|
+
*
|
|
65
|
+
* @param view - The view.
|
|
66
|
+
* @param x - Pixels from the left.
|
|
67
|
+
* @param y - Pixels from the top.
|
|
68
|
+
* @returns `lon` in -180 up to 180 and `lat`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { unprojectFlat } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
73
|
+
*
|
|
74
|
+
* console.log(unprojectFlat({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 360, 180));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function unprojectFlat(view, x, y) {
|
|
78
|
+
const k = pixelsPerDegree(view);
|
|
79
|
+
return { lon: wrapLongitude(view.centerLon + (x - view.width / 2) / k), lat: view.centerLat - (y - view.height / 2) / k };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The view kept inside what the map can show: the zoom between 1 and 8, the longitude wrapped, and the middle's latitude so that the poles are never further in than the box's edges.
|
|
83
|
+
*
|
|
84
|
+
* @param view - The view asked for.
|
|
85
|
+
* @returns The view to use.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { clampView } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
90
|
+
*
|
|
91
|
+
* console.log(clampView({ width: 720, height: 360, centerLon: 200, centerLat: 40, zoom: 1 }));
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function clampView(view) {
|
|
95
|
+
const zoom = Math.min(MAX_ZOOM, Math.max(1, Number.isFinite(view.zoom) ? view.zoom : 1));
|
|
96
|
+
const next = { ...view, zoom, centerLon: wrapLongitude(Number.isFinite(view.centerLon) ? view.centerLon : 0) };
|
|
97
|
+
const limit = Math.max(0, 90 - view.height / 2 / pixelsPerDegree(next));
|
|
98
|
+
next.centerLat = Math.min(limit, Math.max(-limit, Number.isFinite(view.centerLat) ? view.centerLat : 0));
|
|
99
|
+
return next;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Zoom by a factor about a point of the box, so the place under that point stays under it.
|
|
103
|
+
*
|
|
104
|
+
* @param view - The view.
|
|
105
|
+
* @param factor - Above 1 zooms in.
|
|
106
|
+
* @param x - Pixels from the left; the middle when left out.
|
|
107
|
+
* @param y - Pixels from the top; the middle when left out.
|
|
108
|
+
* @returns The new view, clamped.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { zoomAbout } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
113
|
+
*
|
|
114
|
+
* console.log(zoomAbout({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 2, 540, 90).zoom);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export function zoomAbout(view, factor, x = view.width / 2, y = view.height / 2) {
|
|
118
|
+
const at = unprojectFlat(view, x, y);
|
|
119
|
+
const zoom = Math.min(MAX_ZOOM, Math.max(1, view.zoom * factor));
|
|
120
|
+
const k = pixelsPerDegree({ ...view, zoom });
|
|
121
|
+
return clampView({ ...view, zoom, centerLon: at.lon - (x - view.width / 2) / k, centerLat: at.lat + (y - view.height / 2) / k });
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Where a satellite is on the Earth, from its place in the satellites' axes (`createSatellites`: Earth radii from the Earth's centre, x to the vernal equinox, y north, z the other way from TEME's y) and how far the Earth has turned
|
|
125
|
+
* (`greenwichSidereal`). The latitude is geodetic (the Earth's flattening is applied to the geocentric one), the height is above 6,371 km.
|
|
126
|
+
*
|
|
127
|
+
* @param x - Earth radii.
|
|
128
|
+
* @param y - Earth radii, north.
|
|
129
|
+
* @param z - Earth radii.
|
|
130
|
+
* @param siderealDeg - Greenwich mean sidereal time in degrees.
|
|
131
|
+
* @returns Longitude in -180 up to 180, latitude and height in kilometres.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { groundPoint } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
136
|
+
*
|
|
137
|
+
* console.log(groundPoint(1.1, 0, 0, 0));
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export function groundPoint(x, y, z, siderealDeg) {
|
|
141
|
+
const r = Math.hypot(x, y, z);
|
|
142
|
+
const lon = wrapLongitude(Math.atan2(-z, x) / RAD - siderealDeg);
|
|
143
|
+
const geocentric = Math.asin(r === 0 ? 0 : y / r);
|
|
144
|
+
return { lon, lat: Math.atan(Math.tan(geocentric) / FLATTENED) / RAD, altitudeKm: (r - 1) * 6371 };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* (1 - f)^2 for the Earth's flattening f = 1/298.257: the factor between the tangent of the geocentric and of the geodetic latitude.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { FLATTENED } from "@johnmorrisdotca/chikyu-earth/flat";
|
|
152
|
+
*
|
|
153
|
+
* console.log(FLATTENED);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export const FLATTENED = 0.99330562;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { clusterPlanes, groupFacts, planeLetter, type FlatElements, type GroupFacts, type Plane, type PlaneClusters, type PlaneOptions } from "./facts.ts";
|
|
2
|
+
export { FLATTENED, MAX_ZOOM, clampView, groundPoint, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout, type FlatView } from "./geometry.ts";
|
|
3
|
+
export { COMPASS_POINTS, SHADOW_RADIUS_KM, compassPoint, inEarthShadow, shadowFlags, sunDirection, sunDirectionScene, trackStateOf, trackStateOfScene, type CompassPoint, type GroundTrackState } from "./track-state.ts";
|
|
4
|
+
export { GROUP_COLOURS, PLANE_COLOURS, SPARE_COLOUR, TRACK_SHADOW, TRACK_SUNLIT } from "./colours.ts";
|
|
5
|
+
export { FLAT_WORDS, type FlatLang } from "./words.ts";
|
|
6
|
+
export type { ChikyuFlat, FlatPick, FlatPlane, GroupStyle } from "./element.ts";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The flat map's pure parts and the element's types (`@johnmorrisdotca/chikyu-earth/flat`): the facts of a group of satellites, the orbital planes, the map's geometry, the colours and words. They import on a server and need no dependency, not even satellite.js.
|
|
2
|
+
// The element itself is in `@johnmorrisdotca/chikyu-earth/flat/define`, which registers `<chikyu-flat>`.
|
|
3
|
+
export { clusterPlanes, groupFacts, planeLetter } from "./facts.js";
|
|
4
|
+
export { FLATTENED, MAX_ZOOM, clampView, groundPoint, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
|
|
5
|
+
export { COMPASS_POINTS, SHADOW_RADIUS_KM, compassPoint, inEarthShadow, shadowFlags, sunDirection, sunDirectionScene, trackStateOf, trackStateOfScene } from "./track-state.js";
|
|
6
|
+
export { GROUP_COLOURS, PLANE_COLOURS, SPARE_COLOUR, TRACK_SHADOW, TRACK_SUNLIT } from "./colours.js";
|
|
7
|
+
export { FLAT_WORDS } from "./words.js";
|