-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSatelliteCoverage.html
More file actions
1647 lines (1450 loc) · 73.5 KB
/
SatelliteCoverage.html
File metadata and controls
1647 lines (1450 loc) · 73.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Satellite Coverage Visualiser</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Anta&family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap" rel="stylesheet">
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://d3js.org/topojson.v3.min.js"></script>
<style>
/* --- Base Styles --- */
body {
margin: 0;
font-family: "Roboto Mono", monospace;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
font-size: 14px;
line-height: 80%;
background-color: #000;
color: #fff;
overflow: hidden; /* Prevents scrollbars from the full-screen map */
}
/* --- Control Panel Styles --- */
#panel-container {
position: absolute;
top: 0px;
left: 0;
z-index: 10; /* Ensures panel is on top of the map */
display: flex;
align-items: flex-start;
flex-shrink: 0;
}
#info {
width: 335px;
max-height: calc(100vh - 25px); /* Full height with a small margin */
overflow-y: auto; /* Scrollable if content overflows */
margin: 5px;
margin-left: 15px;
padding: 5px;
background: rgba(0, 0, 0, 0.1); /* Semi-transparent background */
border-radius: 10px;
backdrop-filter: blur(3px); /* Frosted glass effect */
box-shadow: 0 0 15px rgba(0,0,0,0.1);
border: 1px solid rgba(190, 153, 5, 1);
transition: all 0.35s ease-in-out; /* Animation for collapsing */
transform: translateX(0); /* Initial state: visible */
}
/* Collapsed state for the panel */
#info.collapsed {
transform: translateX(-100%); /* Slides panel off-screen */
width: 0px;
padding-left: 0;
padding-right: 0;
margin-left: 0;
overflow-x: hidden;
}
#toggle-button {
position: absolute;
top: 5%;
left: 100%; /* Sits just to the right of the panel */
transform: translateX(0);
width: 48px;
height: 48px;
padding: 0;
padding-left: 2px;
background: #BE9905;
border: 0px solid #666;
border-left: none;
color: white;
cursor: pointer;
border-radius: 0 8px 8px 0;
font-size: 1.0em;
line-height: 48px;
text-align: center;
z-index: 10;
transition: all 0.35s ease-in-out;
}
/* Style for the toggle button when the panel is collapsed */
#info.collapsed + #toggle-button {
transform: translateX(-10%); /* Sits slightly on top of the collapsed panel */
background: #ed1248; /* Change color to indicate 'open' action */
}
/* --- UI Element Styles --- */
h1 {
margin-top: 0;
font-size: 1.8em;
text-align: center;
color: #BE9905;
font-family: "Anta", sans-serif;
font-weight: 400;
font-style: normal;
line-height: 120%;
}
h2 {
font-size: 0.9em;
color: #BE9905;
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 20px;
margin-bottom: 10px;
border-bottom: 1px solid #444;
padding-bottom: 5px;
line-height: 120%;
font-family: "Anta", sans-serif;
font-weight: 400;
font-style: normal;
}
.control-group { margin-bottom: 12px; }
label { display: block; margin-bottom: 5px; font-weight: bold; font-size: 0.9em; }
/* Custom styles for range sliders */
input[type="range"] {
width: 100%;
-webkit-appearance: none;
appearance: none;
height: 5px;
background: #555;
outline: none;
border-radius: 5px;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
background: #BE9905;
cursor: pointer;
border-radius: 50%;
border: 2px solid #000;
}
input[type="range"]::-moz-range-thumb {
width: 16px;
height: 16px;
background: #BE9905;
cursor: pointer;
border-radius: 50%;
border: 2px solid #000;
}
/* Value displays (e.g., "1234 km") */
.value { float: right; font-weight: normal; color: #ccc; }
/* Key-value pair display for satellite state */
.display-item {
display: flex;
justify-content: space-between;
font-size: 0.9em;
padding: 5px 0;
border-bottom: 1px solid #333;
}
.display-item:last-child { border-bottom: none; }
.display-label { color: #aaa; }
.display-value { font-weight: bold; }
/* Warning message for low perigee */
.warning {
font-size: 0.85em;
font-weight: bold;
text-align: center;
padding: 6px;
margin-top: 5px;
border-radius: 4px;
display: none; /* Hidden by default */
}
.warning.amber { display: block; background-color: #5d4500; color: #ffc107; }
.warning.red { display: block; background-color: #5d1a1a; color: #ff5252; }
.display-group { margin-bottom: 12px; }
/* --- Map Styles --- */
#map-container {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
min-width: 0;
}
/* Canvas for the coverage heatmap (sits below the SVG) */
#heatmap-canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
/* SVG for map outlines, satellite markers, and tracks (sits on top) */
#map-svg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2; /* SVG on top of canvas */
background-color: transparent;
}
/* --- SVG Element Styles --- */
.coastline {
fill: none;
stroke: #5d9732;
stroke-width: 0.5px;
}
.graticule { /* Latitude/Longitude grid lines */
fill: none;
stroke: #333;
stroke-width: 0.5px;
stroke-dasharray: 2,2;
}
.satellite {
/* Fill is set dynamically in JS */
stroke: #fff;
stroke-width: 1.5px;
}
.ground-track-1 { fill: none; stroke: #BE9905; stroke-width: 1.5px; opacity: 0.7; }
.ground-track-2 { fill: none; stroke: #1a5dad; stroke-width: 1.5px; opacity: 0.7; }
.ground-track-3 { fill: none; stroke: #ed1248; stroke-width: 1.5px; opacity: 0.7; }
/* --- Tab Styles --- */
.tabs {
display: flex;
justify-content: space-around;
margin-bottom: 10px;
}
.tab-button {
flex-grow: 1;
padding: 8px 5px;
background-color: #333;
color: #ddd;
border: 1px solid #555;
cursor: pointer;
font-family: "Roboto Mono", monospace;
transition: background-color 0.2s, color 0.2s;
border-radius: 5px 5px 0 0;
}
.tab-button:not(:last-child) { border-right: none; }
.tab-button.active {
background-color: #BE9905;
color: #000;
font-weight: bold;
}
.tab-content { display: none; } /* All tabs hidden by default */
.tab-content.active { display: block; } /* Active tab is shown */
/* --- Toggle Switch Styles --- */
.toggle-switch {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.switch {
position: relative;
display: inline-block;
width: 50px;
height: 24px;
}
.switch input { display: none; } /* Hide the actual checkbox */
.slider { /* The visible part of the switch */
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background-color: #555;
transition: .4s;
border-radius: 24px;
}
.slider:before { /* The sliding knob */
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider { background-color: #BE9905; }
input:checked + .slider:before { transform: translateX(26px); }
/* --- Other UI Styles --- */
input[type="datetime-local"] {
width: 100%;
background-color: #333;
color: #fff;
border: 1px solid #555;
border-radius: 5px;
padding: 0px;
font-family: "Roboto Mono", monospace;
}
#sim-time-display {
font-size: 1.1em;
color: #BE9905;
text-align: center;
padding: 10px;
background: #222;
border-radius: 5px;
margin-bottom: 15px;
}
/* Styles for coverage statistic bars */
.stat-bar {
width: 100%;
background-color: #333;
border-radius: 3px;
margin: 2px 0 8px 0;
overflow: hidden;
}
.stat-bar-fill {
height: 10px;
background-color: #BE9905;
width: 0%; /* Width is set dynamically by JS */
transition: width 0.5s ease-out; /* Animate bar changes */
border-radius: 3px;
}
/* Satellite-specific colors for text */
.sat-1-color { color: #BE9905; }
.sat-2-color { color: #1a5dad; }
.sat-3-color { color: #ed1248; }
/* --- Button Style --- */
.sim-button {
width: 100%;
padding: 10px;
background-color: #BE9905;
color: #000;
border: none;
border-radius: 5px;
font-family: "Roboto Mono", monospace;
font-weight: bold;
font-size: 1em;
cursor: pointer;
margin-top: 10px;
}
.sim-button:hover {
background-color: #ffd966;
}
.sim-button:disabled {
background-color: #555;
color: #999;
cursor: not-allowed;
}
</style>
</head>
<body>
<div id="panel-container">
<div id="info">
<h1>Coverage Visualiser</h1>
<div class="tabs">
<button class="tab-button" onclick="openTab(event, 'sat-1')">Sat 1</button>
<button class="tab-button" onclick="openTab(event, 'sat-2')">Sat 2</button>
<button class="tab-button" onclick="openTab(event, 'sat-3')">Sat 3</button>
<button class="tab-button active" onclick="openTab(event, 'sim')">Sim</button>
</div>
<div id="sat-1" class="tab-content ">
<h2 class="sat-1-color">SATELLITE 1 ORBIT</h2>
<div class="control-group">
<label for="a-1">Semi-major Axis (<i>a</i>) <span class="value" id="a-1_val"></span> km</label>
<input type="range" id="a-1" min="6600" max="50000" step="1" value="26562.4">
</div>
<div class="control-group">
<label for="e-1">Eccentricity (<i>e</i>) <span class="value" id="e-1_val"></span></label>
<input type="range" id="e-1" min="0" max="0.95" step="0.001" value="0.74">
</div>
<div class="control-group">
<label for="i-1">Inclination (<i>i</i>) <span class="value" id="i-1_val"></span>°</label>
<input type="range" id="i-1" min="0" max="180" step="0.1" value="63.4349">
</div>
<div class="control-group">
<label for="raan_0-1">Initial RAAN (<i>Ω<sub>0</sub></i>) <span class="value" id="raan_0-1_val"></span>°</label>
<input type="range" id="raan_0-1" min="0" max="360" step="0.1" value="270">
</div>
<div class="control-group">
<label for="aop_0-1">Initial Argument of Perigee (<i>ω<sub>0</sub></i>) <span class="value" id="aop_0-1_val"></span>°</label>
<input type="range" id="aop_0-1" min="0" max="360" step="0.1" value="270">
</div>
<div class="control-group">
<label for="m0-1">Initial Mean Anomaly (<i>M<sub>0</sub></i>) <span class="value" id="m0-1_val"></span>°</label>
<input type="range" id="m0-1" min="0" max="360" step="0.1" value="0">
</div>
<div id="perigee_warning-1" class="warning"></div>
<h2 class="sat-1-color">SATELLITE 1 COVERAGE</h2>
<div class="control-group">
<label for="fov-1">Field of View (<i>FOV</i>) <span class="value" id="fov-1_val"></span>°</label>
<input type="range" id="fov-1" min="1" max="120" step="1" value="45">
</div>
<div class="toggle-switch">
<label>Show Ground Track</label>
<label class="switch">
<input type="checkbox" id="track-1" checked>
<span class="slider"></span>
</label>
</div>
<div class="toggle-switch">
<label>Show Coverage Area</label>
<label class="switch">
<input type="checkbox" id="cov-1" checked>
<span class="slider"></span>
</label>
</div>
<h2 class="sat-1-color">SATELLITE 1 STATE</h2>
<div class="display-group">
<div class="display-item"><span class="display-label">True Anomaly (<i>ν</i>)</span><span class="display-value" id="nu_val-1">0.0°</span></div>
<div class="display-item"><span class="display-label">Altitude</span><span class="display-value" id="alt_val-1">0 km</span></div>
<div class="display-item"><span class="display-label">Current RAAN (<i>Ω</i>)</span><span class="display-value" id="raan_val-1">0.0°</span></div>
<div class="display-item"><span class="display-label">Current AoP (<i>ω</i>)</span><span class="display-value" id="aop_val-1">0.0°</span></div>
<div class="display-item"><span class="display-label">RAAN Rate (<i>Ω̇</i>)</span><span class="display-value" id="raan_dot_val-1">0.0°/day</span></div>
<div class="display-item"><span class="display-label">AoP Rate (<i>ω̇</i>)</span><span class="display-value" id="aop_dot_val-1">0.0°/day</span></div>
</div>
</div>
<div id="sat-2" class="tab-content">
<h2 class="sat-2-color">SATELLITE 2 ORBIT</h2>
<div class="control-group">
<label for="a-2">Semi-major Axis (<i>a</i>) <span class="value" id="a-2_val"></span> km</label>
<input type="range" id="a-2" min="6600" max="50000" step="0" value="26562.4">
</div>
<div class="control-group">
<label for="e-2">Eccentricity (<i>e</i>) <span class="value" id="e-2_val"></span></label>
<input type="range" id="e-2" min="0" max="0.95" step="0.001" value="0.74">
</div>
<div class="control-group">
<label for="i-2">Inclination (<i>i</i>) <span class="value" id="i-2_val"></span>°</label>
<input type="range" id="i-2" min="0" max="180" step="0.1" value="63.4349">
</div>
<div class="control-group">
<label for="raan_0-2">Initial RAAN (<i>Ω<sub>0</sub></i>) <span class="value" id="raan_0-2_val"></span>°</label>
<input type="range" id="raan_0-2" min="0" max="360" step="0.1" value="90">
</div>
<div class="control-group">
<label for="aop_0-2">Initial Argument of Perigee (<i>ω<sub>0</sub></i>) <span class="value" id="aop_0-2_val"></span>°</label>
<input type="range" id="aop_0-2" min="0" max="360" step="0.1" value="270">
</div>
<div class="control-group">
<label for="m0-2">Initial Mean Anomaly (<i>M<sub>0</sub></i>) <span class="value" id="m0-2_val"></span>°</label>
<input type="range" id="m0-2" min="0" max="360" step="0.1" value="180">
</div>
<div id="perigee_warning-2" class="warning"></div>
<h2 class="sat-2-color">SATELLITE 2 COVERAGE</h2>
<div class="control-group">
<label for="fov-2">Field of View (<i>FOV</i>) <span class="value" id="fov-2_val"></span>°</label>
<input type="range" id="fov-2" min="1" max="120" step="1" value="45">
</div>
<div class="toggle-switch">
<label>Show Ground Track</label>
<label class="switch">
<input type="checkbox" id="track-2" checked>
<span class="slider"></span>
</label>
</div>
<div class="toggle-switch">
<label>Show Coverage Area</label>
<label class="switch">
<input type="checkbox" id="cov-2" checked>
<span class="slider"></span>
</label>
</div>
<h2 class="sat-2-color">SATELLITE 2 STATE</h2>
<div class="display-group">
<div class="display-item"><span class="display-label">True Anomaly (<i>ν</i>)</span><span class="display-value" id="nu_val-2">0.0°</span></div>
<div class="display-item"><span class="display-label">Altitude</span><span class="display-value" id="alt_val-2">0 km</span></div>
<div class="display-item"><span class="display-label">Current RAAN (<i>Ω</i>)</span><span class="display-value" id="raan_val-2">0.0°</span></div>
<div class="display-item"><span class="display-label">Current AoP (<i>ω</i>)</span><span class="display-value" id="aop_val-2">0.0°</span></div>
<div class="display-item"><span class="display-label">RAAN Rate (<i>Ω̇</i>)</span><span class="display-value" id="raan_dot_val-2">0.0°/day</span></div>
<div class="display-item"><span class="display-label">AoP Rate (<i>ω̇</i>)</span><span class="display-value" id="aop_dot_val-2">0.0°/day</span></div>
</div>
</div>
<div id="sat-3" class="tab-content">
<h2 class="sat-3-color">SATELLITE 3 ORBIT</h2>
<div class="control-group">
<label for="a-3">Semi-major Axis (<i>a</i>) <span class="value" id="a-3_val"></span> km</label>
<input type="range" id="a-3" min="6600" max="50000" step="1" value="7071.137">
</div>
<div class="control-group">
<label for="e-3">Eccentricity (<i>e</i>) <span class="value" id="e-3_val"></span></label>
<input type="range" id="e-3" min="0" max="0.95" step="0.001" value="0.0">
</div>
<div class="control-group">
<label for="i-3">Inclination (<i>i</i>) <span class="value" id="i-3_val"></span>°</label>
<input type="range" id="i-3" min="0" max="180" step="0.1" value="98.18">
</div>
<div class="control-group">
<label for="raan_0-3">Initial RAAN (<i>Ω<sub>0</sub></i>) <span class="value" id="raan_0-3_val"></span>°</label>
<input type="range" id="raan_0-3" min="0" max="360" step="0.1" value="240">
</div>
<div class="control-group">
<label for="aop_0-3">Initial Argument of Perigee (<i>ω<sub>0</sub></i>) <span class="value" id="aop_0-3_val"></span>°</label>
<input type="range" id="aop_0-3" min="0" max="360" step="0.1" value="270">
</div>
<div class="control-group">
<label for="m0-3">Initial Mean Anomaly (<i>M<sub>0</sub></i>) <span class="value" id="m0-3_val"></span>°</label>
<input type="range" id="m0-3" min="0" max="360" step="0.1" value="0">
</div>
<div id="perigee_warning-3" class="warning"></div>
<h2 class="sat-3-color">SATELLITE 3 COVERAGE</h2>
<div class="control-group">
<label for="fov-3">Field of View (<i>FOV</i>) <span class="value" id="fov-3_val"></span>°</label>
<input type="range" id="fov-3" min="1" max="120" step="1" value="110">
</div>
<div class="toggle-switch">
<label>Show Ground Track</label>
<label class="switch">
<input type="checkbox" id="track-3" checked>
<span class="slider"></span>
</label>
</div>
<div class="toggle-switch">
<label>Show Coverage Area</label>
<label class="switch">
<input type="checkbox" id="cov-3" checked>
<span class="slider"></span>
</label>
</div>
<h2 class="sat-3-color">SATELLITE 3 STATE</h2>
<div class="display-group">
<div class="display-item"><span class="display-label">True Anomaly (<i>ν</i>)</span><span class="display-value" id="nu_val-3">0.0°</span></div>
<div class="display-item"><span class="display-label">Altitude</span><span class="display-value" id="alt_val-3">0 km</span></div>
<div class="display-item"><span class="display-label">Current RAAN (<i>Ω</i>)</span><span class="display-value" id="raan_val-3">0.0°</span></div>
<div class="display-item"><span class="display-label">Current AoP (<i>ω</i>)</span><span class="display-value" id="aop_val-3">0.0°</span></div>
<div class="display-item"><span class="display-label">RAAN Rate (<i>Ω̇</i>)</span><span class="display-value" id="raan_dot_val-3">0.0°/day</span></div>
<div class="display-item"><span class="display-label">AoP Rate (<i>ω̇</i>)</span><span class="display-value" id="aop_dot_val-3">0.0°/day</span></div>
</div>
</div>
<div id="sim" class="tab-content active">
<h2>SIMULATION CONTROLS</h2>
<div class="control-group">
<label for="epoch">Epoch (UTC)</label>
<input type="datetime-local" id="epoch">
</div>
<div class="control-group">
<label for="speed">Simulation Speed <span class="value" id="speed_val">x500</span></label>
<input type="range" id="speed" min="0" max="5000" step="1" value="500">
</div>
<button id="reset-sim-btn" class="sim-button">Reset to Epoch</button>
<h2>SIMULATION STATE</h2>
<div id="sim-time-display"></div>
</div>
<div id="coverage-stats">
<h2>COVERAGE STATISTICS</h2>
<div class="display-item">
<span class="display-label">0 Satellites</span>
<span class="display-value" id="stat-0">0%</span> </div>
<div class="stat-bar"><div id="stat-bar-0" class="stat-bar-fill"></div></div>
<div class="display-item">
<span class="display-label">1 Satellite</span>
<span class="display-value" id="stat-1">0%</span> </div>
<div class="stat-bar"><div id="stat-bar-1" class="stat-bar-fill"></div></div>
<div class="display-item">
<span class="display-label">2 Satellites</span>
<span class="display-value" id="stat-2">0%</span> </div>
<div class="stat-bar"><div id="stat-bar-2" class="stat-bar-fill"></div></div>
<div class="display-item">
<span class="display-label">3 Satellites</span>
<span class="display-value" id="stat-3">0%</span> </div>
<div class="stat-bar"><div id="stat-bar-3" class="stat-bar-fill"></div></div>
</div>
</div>
<button id="toggle-button" title="Toggle Controls">◀</button>
</div>
<div id="map-container">
<canvas id="heatmap-canvas" width="1080" height="540"></canvas>
<svg id="map-svg"></svg>
</div>
<script id="stats-worker" type="text/worker">
// --- Constants (must be redefined in worker scope) ---
const EARTH_RADIUS_KM = 6378.137;
const DEG_TO_RAD = Math.PI / 180;
const RAD_TO_DEG = 180 / Math.PI;
/**
* (Worker copy) Checks if a point on Earth's surface is visible to a satellite.
* This is a duplicate of the main thread's function, simplified for worker use.
*/
function isPointVisible(pointECEF, satPos, r_sat, nadir, nadirMag, fov_rad, horizon_angle_rad) {
// 1. Horizon Check: Is the point behind the Earth?
const dot_center = pointECEF.x * satPos.x +
pointECEF.y * satPos.y +
pointECEF.z * satPos.z;
const angle_center_sq_cos = dot_center / (EARTH_RADIUS_KM * r_sat);
const angle_center = Math.acos(Math.max(-1, Math.min(1, angle_center_sq_cos)));
if (angle_center > horizon_angle_rad) {
return false;
}
// 2. FOV Check: Is the point within the sensor's field of view?
const vec_sat_to_point = {
x: pointECEF.x - satPos.x,
y: pointECEF.y - satPos.y,
z: pointECEF.z - satPos.z
};
const satToPointMag = Math.sqrt(vec_sat_to_point.x**2 + vec_sat_to_point.y**2 + vec_sat_to_point.z**2);
const dot_fov = vec_sat_to_point.x * nadir.x +
vec_sat_to_point.y * nadir.y +
vec_sat_to_point.z * nadir.z;
const angle_fov_sq_cos = dot_fov / (satToPointMag * nadirMag);
const angle_fov = Math.acos(Math.max(-1, Math.min(1, angle_fov_sq_cos)));
return angle_fov <= fov_rad;
}
/**
* (Worker copy) Converts Lat/Lon (degrees) to ECEF coordinates (km).
*/
function latLonToECEF(lat_deg, lon_deg, alt_km) {
const lat_rad = lat_deg * DEG_TO_RAD;
const lon_rad = lon_deg * DEG_TO_RAD;
const r = alt_km;
return {
x: r * Math.cos(lat_rad) * Math.cos(lon_rad),
y: r * Math.cos(lat_rad) * Math.sin(lon_rad),
z: r * Math.sin(lat_rad)
};
}
// --- Worker Message Handler ---
/**
* Listens for messages from the main thread.
* e.data will contain the current parameters for all active satellites.
*/
self.onmessage = function(e) {
const satParams = e.data; // Array of satellite parameters
const numSamples = 50000; // Number of random points to test (Monte Carlo)
let counts = [0, 0, 0, 0]; // Index = number of satellites (0, 1, 2, or 3)
if (satParams.length === 0) {
postMessage(counts); // Send back empty counts if no sats
return;
}
// Run the Monte Carlo simulation
for (let i = 0; i < numSamples; i++) {
// Generate a random point uniformly distributed on the sphere
// See: http://mathworld.wolfram.com/SpherePointPicking.html
const u = Math.random();
const v = Math.random();
const lon = 360 * u - 180;
const lat = Math.acos(2 * v - 1) * RAD_TO_DEG - 90;
const pointECEF = latLonToECEF(lat, lon, EARTH_RADIUS_KM);
let coverageCount = 0;
// Check this point against each satellite
satParams.forEach(params => {
if (isPointVisible(pointECEF, params.satPos, params.r_sat, params.nadir, params.nadirMag, params.fov_rad, params.horizon_angle_rad)) {
coverageCount++;
}
});
// Increment the appropriate counter
counts[coverageCount]++;
}
// Send the results (counts and total samples) back to the main thread
postMessage({counts, numSamples});
};
</script>
<script>
// --- Global Constants ---
const EARTH_RADIUS_KM = 6378.137; // WGS-84 Equatorial Radius
const MU_EARTH = 398600.4418; // Earth's gravitational parameter (km^3/s^2)
const J2_COEFF = 0.00108262668; // J2 gravitational coefficient (for perturbations)
const EARTH_ROTATION_RAD_S = 7.2921150e-5; // Earth rotation rate (radians/second)
const DEG_TO_RAD = Math.PI / 180; // Conversion factor
const RAD_TO_DEG = 180 / Math.PI; // Conversion factor
// --- Global State ---
let svg, projection, path, graticule; // D3 map objects
let heatmapCtx, heatmapWidth, heatmapHeight; // Heatmap canvas objects
let lastTimestamp = 0; // For calculating animation frame delta time
let epochDate = new Date(); // The "T=0" for the simulation
let currentSimDate = new Date(); // The "current" time in the simulation
let epochGST = 0; // Greenwich Sidereal Time at epoch
let elapsedSimSeconds = 0; // Total sim seconds passed since epoch
let satelliteStates = [{}, {}, {}]; // Stores propagated state {ecef, latLon, ...} for each sat
let groundTracks = [[], [], []]; // Stores array of [lon, lat, timestamp] for each sat's track
let lastStatsUpdateTime = 0; // Throttles updates to the stats worker
let statsWorker; // The Web Worker for calculating stats
let pixelToGeoCache = []; // Performance cache: [ {ecef: {x,y,z}}, ... ] for each heatmap pixel
// --- DOM Element Cache ---
// Caching all DOM elements we need to interact with improves performance.
const dom = {
infoDiv: document.getElementById('info'),
toggleButton: document.getElementById('toggle-button'),
mapContainer: document.getElementById('map-container'),
heatmapCanvas: document.getElementById('heatmap-canvas'),
mapSvg: document.getElementById('map-svg'),
epochInput: document.getElementById('epoch'),
speedSlider: document.getElementById('speed'),
speedValue: document.getElementById('speed_val'),
simTimeDisplay: document.getElementById('sim-time-display'),
resetSimBtn: document.getElementById('reset-sim-btn'),
stats: {
val: [ // Statistics text (e.g., "50%")
document.getElementById('stat-0'),
document.getElementById('stat-1'),
document.getElementById('stat-2'),
document.getElementById('stat-3')
],
bar: [ // Statistics bar fill divs
document.getElementById('stat-bar-0'),
document.getElementById('stat-bar-1'),
document.getElementById('stat-bar-2'),
document.getElementById('stat-bar-3')
]
},
sats: [1, 2, 3].map(i => ({ // Cache for each satellite's UI controls
a: document.getElementById(`a-${i}`),
e: document.getElementById(`e-${i}`),
i: document.getElementById(`i-${i}`),
raan_0: document.getElementById(`raan_0-${i}`),
aop_0: document.getElementById(`aop_0-${i}`),
m0: document.getElementById(`m0-${i}`),
fov: document.getElementById(`fov-${i}`),
track: document.getElementById(`track-${i}`), // Checkbox
cov: document.getElementById(`cov-${i}`), // Checkbox
val: { // Value display spans
a: document.getElementById(`a-${i}_val`),
e: document.getElementById(`e-${i}_val`),
i: document.getElementById(`i-${i}_val`),
raan_0: document.getElementById(`raan_0-${i}_val`),
aop_0: document.getElementById(`aop_0-${i}_val`),
m0: document.getElementById(`m0-${i}_val`),
fov: document.getElementById(`fov-${i}_val`),
nu: document.getElementById(`nu_val-${i}`),
alt: document.getElementById(`alt_val-${i}`),
raan_current: document.getElementById(`raan_val-${i}`),
aop_current: document.getElementById(`aop_val-${i}`),
raan_dot: document.getElementById(`raan_dot_val-${i}`),
aop_dot: document.getElementById(`aop_dot_val-${i}`)
},
warning: document.getElementById(`perigee_warning-${i}`)
}))
};
// --- Main Initialization Function ---
/**
* This is the entry point for the application.
* It sets up the UI, worker, and map, then starts the simulation loop.
*/
function init() {
setupUI();
initStatsWorker();
initMap();
resetSimulation(); // Set initial simulation time and state
requestAnimationFrame(simulationLoop); // Start the loop
window.addEventListener('resize', onWindowResize); // Handle window resizing
}
// --- UI Setup ---
/**
* Attaches all necessary event listeners to the UI elements.
*/
function setupUI() {
// Panel collapse toggle button
dom.toggleButton.addEventListener('click', () => {
dom.infoDiv.classList.toggle('collapsed');
dom.toggleButton.textContent = dom.infoDiv.classList.contains('collapsed') ? '▶' : '◀';
});
// Set initial epoch time to the user's current local time
const now = new Date();
now.setMinutes(now.getMinutes() - now.getTimezoneOffset()); // Adjust for local timezone
now.setMilliseconds(null); // Clean up
now.setSeconds(null); // Clean up
dom.epochInput.value = now.toISOString().slice(0, 16);
dom.epochInput.addEventListener('change', resetSimulation); // Reset sim on change
// Simulation speed slider
dom.speedSlider.addEventListener('input', () => {
dom.speedValue.textContent = `x${dom.speedSlider.value}`;
});
// Reset simulation button
dom.resetSimBtn.addEventListener('click', resetSimulation);
// Satellite control sliders
dom.sats.forEach((sat, index) => {
// Function to update the text display next to a slider
const updateFn = () => updateSatelliteUI(index);
// Add listeners to all orbital parameter sliders
sat.a.addEventListener('input', updateFn);
sat.e.addEventListener('input', updateFn);
sat.i.addEventListener('input', updateFn);
sat.raan_0.addEventListener('input', updateFn);
sat.aop_0.addEventListener('input', updateFn);
sat.m0.addEventListener('input', updateFn);
sat.fov.addEventListener('input', updateFn);
// Add listener to the 'Show Ground Track' toggle
sat.track.addEventListener('change', () => {
if (!sat.track.checked) {
// If unchecked, clear the track data
groundTracks[index] = [];
d3.select(`#track-${index}`).datum({ type: "LineString", coordinates: [] }).attr('d', path);
}
});
// Set the initial text values on load
updateSatelliteUI(index);
});
}
/**
* Updates the text values next to the sliders for a given satellite.
* Also checks for and displays orbital warnings (e.g., low perigee).
*/
function updateSatelliteUI(index) {
const sat = dom.sats[index];
const a = parseFloat(sat.a.value);
const e = parseFloat(sat.e.value);
// Update text values
sat.val.a.textContent = a.toFixed(0);
sat.val.e.textContent = e.toFixed(3);
sat.val.i.textContent = parseFloat(sat.i.value).toFixed(1);
sat.val.raan_0.textContent = parseFloat(sat.raan_0.value).toFixed(1);
sat.val.aop_0.textContent = parseFloat(sat.aop_0.value).toFixed(1);
sat.val.m0.textContent = parseFloat(sat.m0.value).toFixed(1);
sat.val.fov.textContent = `${sat.fov.value}°`;
// Perigee Warning
const perigee_alt = a * (1 - e) - EARTH_RADIUS_KM;
sat.warning.className = 'warning'; // Reset warning
sat.warning.textContent = '';
if (perigee_alt < 80) {
// Altitude is too low, will re-enter
sat.warning.classList.add('red');
sat.warning.textContent = 'WARNING: Atmospheric re-entry!';
} else if (perigee_alt < 250) {
// Altitude is low, high drag
sat.warning.classList.add('amber');
sat.warning.textContent = 'CAUTION: High atmospheric drag.';
}
}
/**
* Handles tab switching logic for the control panel.
*/
function openTab(evt, tabName) {
let i, tabcontent, tabbuttons;
// Hide all tab content
tabcontent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Deactivate all tab buttons
tabbuttons = document.getElementsByClassName("tab-button");
for (i = 0; i < tabbuttons.length; i++) {
tabbuttons[i].className = tabbuttons[i].className.replace(" active", "");
}
// Show the selected tab content and activate its button
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
// --- Stats Worker Setup ---
/**
* Initializes the Web Worker that calculates coverage statistics.
* It creates the worker from the inline <script> tag.
*/
function initStatsWorker() {
try {
// Create a Blob from the worker script text
const blob = new Blob([document.getElementById('stats-worker').textContent], { type: 'application/javascript' });
// Create a worker from the Blob's URL
statsWorker = new Worker(URL.createObjectURL(blob));
// Define what to do when the worker sends results back
statsWorker.onmessage = function(e) {
const { counts, numSamples } = e.data;
// Update the UI with the new statistics
counts.forEach((count, i) => {
const percent = (count / numSamples) * 100;
const roundedPercent = Math.round(percent);
dom.stats.val[i].textContent = `${roundedPercent}%`; // Update text
dom.stats.bar[i].style.width = `${roundedPercent}%`; // Update bar width
});
};
statsWorker.onerror = function(error) {
console.error("StatsWorker error:", error.message);
};
} catch (err) {
console.error("Failed to initialize Stats Worker:", err);
}
}
// --- Map Initialization ---
/**
* Sets up the D3.js map projection, paths, and SVG layers.
* Loads the world map geography.
*/
function initMap() {
svg = d3.select("#map-svg");
heatmapCtx = dom.heatmapCanvas.getContext('2d', { willReadFrequently: true });
heatmapWidth = dom.heatmapCanvas.width;
heatmapHeight = dom.heatmapCanvas.height;
// Use an Equirectangular projection (simple lat/lon to x/y)
projection = d3.geoEquirectangular().translate([0, 0]).scale(1);
// Create a D3 path generator for this projection
path = d3.geoPath(projection);
// Create <g> groups to act as layers (for z-ordering)
svg.append("g").attr("id", "graticule-layer"); // Longitude/latitude lines
svg.append("g").attr("id", "coastline-layer"); // Land outlines
svg.append("g").attr("id", "track-layer"); // Satellite ground tracks
svg.append("g").attr("id", "satellite-layer"); // Satellite markers
// Draw the graticule (lat/lon grid)
graticule = d3.geoGraticule();
svg.select("#graticule-layer").append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
// Load world map data (TopoJSON format)
d3.json("https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json").then(world => {
// Draw the coastline
svg.select("#coastline-layer").append("path")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "coastline")
.attr("d", path);
// Fit map to screen *after* loading
onWindowResize();
});
// Add <path> elements for each satellite's ground track
svg.select("#track-layer").append("path").attr("id", "track-0").attr("class", "ground-track-1");
svg.select("#track-layer").append("path").attr("id", "track-1").attr("class", "ground-track-2");
svg.select("#track-layer").append("path").attr("id", "track-2").attr("class", "ground-track-3");
// Add <circle> elements for each satellite's marker
svg.select("#satellite-layer").selectAll(".satellite")
.data([0, 1, 2]) // Bind data [0, 1, 2]
.enter().append("circle") // Create 3 circles
.attr("id", d => `sat-marker-${d}`)
.attr("class", "satellite")
.attr("r", 5)
.style("fill", d => ["#BE9905", "#1a5dad", "#ed1248"][d]); // Assign colors
// Call resize handler to set initial map size
onWindowResize();
}
/**
* Pre-calculates the ECEF coordinates for every pixel in the heatmap canvas.
* This is a major performance optimization. Instead of converting pixels
* to [lon, lat] and then to ECEF *every frame*, we do it once here
* and store the ECEF coordinate.
*/
function updatePixelToGeoCache() {