-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathorigCode.txt
More file actions
734 lines (663 loc) · 27.8 KB
/
origCode.txt
File metadata and controls
734 lines (663 loc) · 27.8 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
This is the original code this mod is based on.
#if false
<!DOCTYPE html>
<html lang = "en" >
< meta charset="utf-8" />
<meta name = viewport content="width=device-width, initial-scale=1">
<!--
MIT License
Copyright(c) 2018 Eric A.Meyer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software, and a link to the original URL
(https://meyerweb.com/eric/ksp/resonant-orbits/) will be provided in the
user interface.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<head>
<title>Resonant Orbit Calculator(Kerbal Space Program)</title>
<style type = "text/css" >
body {font: 1em Lucida Grande, Helvetica, Arial, sans-serif;}
body > * {box-sizing: border-box;}
#debug {background-color: rgba(255,255,0,0.2); white-space: pre-wrap;}
#text {margin: 0 15% 3em;}
#text h1 {font-size: 1.9em; letter-spacing: -0.05ch; margin-bottom: 0;}
#text h2 {font-size: smaller; text-transform: uppercase; opacity: 0.5; font-weight: 100; margin: 0.1em 0 1em;}
section {display: flex; justify-content: center;}
form h3
{
font-size: 1em; border-left: 11em solid silver;
padding: 0.25em 0.5em 0; margin: 0 0 0.75em;
}
form {font-size: 0.85em;}
form ul { margin: 0 0 2em; padding: 0; }
form ul li {display: flex; align-items: baseline; margin: 0.2em 0; justify-content: flex-start;}
form ul li > label {width: 11em; padding-right: 0.5em; text-align: right; color: rgba(0,0,0,0.67);}
form ul li input[type = "checkbox"]:checked ~label { display: block; }
form ul li span > label {display: none;}
form ul li span > label span { display: inline-block; width: 2.5em; color: rgba(0,0,0,0.6); }
form ul li input
{
margin-right: 0.25em; border-width: 0 0 1px; border-color: #999; border-style: solid; font-size: inherit;}
form ul li input [size="1"] { width: 3.5em; }
form ul li input [size="12"] { width: 8em; }
form ul li input [disabled] { color: inherit; background: inherit; border - width: 0 0 0; }
form ul li b [id*="set"] { font - size: 115 %; line - height: 0.9; cursor: pointer; }
form ul li.button:hover
{
background: url(arrow - right.svg) 95 % 50 % / auto 0.8em no - repeat;
animation: remind 5s 0s linear alternate infinite;
}
form ul li.button:hover b [id*="set"] { color: green; }
form ul li.button b [id*="set"]:hover
{
background - color: #EE0; border-radius: 50%;}
#parameters .warning {color: rgb(216,0,0);}
#parameters .urgent {font-weight: bold; background: yellow;}
#chart .warning {stroke: rgb(216,0,0);}
#constellation.warning {animation: flicker 2s linear alternate infinite;}
#parameters {flex-shrink: 0;}
#schematic {margin: 0 2em 0 1em; position: relative;}
#schematic > header:not(:empty) {position: absolute; top: 0; left: 0;
width: 100 %; padding: 0.25em;
box - sizing: border - box;
font - size: smaller; text - align: center; white - space: pre - wrap; line - height: 1.3;
color: rgba(0, 0, 0, 0.5); background: hsla(120, 20 %, 80 %, 0.75);
}
# chart {border: 1px solid rgba(0,0,0,0.1); height: 500px; width: 500px; background: #EEE;}
# chart {display: block; margin: 0 auto;}
# chart textPath tspan {fill: #555;}
# chart textPath:hover tspan {fill: #333;}
# setGeo, #setLOS {cursor: pointer;}
footer
{
padding: 0.5em 0.25em; border - top: 1px solid silver; margin - top: 5em;
font - size: smaller; color: rgba(0, 0, 0, 0.5);
}
footer p { margin: 0; line - height: 1.5; text - align: center; }
@supports (display: grid) {
body {
display: grid;
grid - template - columns: min - content;
justify - content: center;
}
# text {margin: 0 0 1em;}
}
@media (max-width: 850px) {
body { display: block; }
# schematic {width: 50vw;}
# chart {width: 100%; height: auto;}
}
@media (max-width: 650px) {
body { display: flex; flex - direction: column; align - items: center; }
# text {order: 10; padding: 1em; margin: 0;}
# text h1 {font-size: 1.5em;}
section { display: block; }
form ul li input {
border - width: 1px; border - color: black; background: #FFE;}
#schematic {width: 100vw; margin: 0;}
#chart {border-width: 1px 0;}
footer { order: 20; margin - top: 1em; }
}
@keyframes remind {
95 % { background - position: 95 % 50 %; }
98 % { background - position: 94 % 50 %; }
100 % { background - position: 95 % 50 %; }
}
@keyframes flicker {
0 % { opacity: 1; }
20 % { opacity: 1; }
33 % { opacity: 0; }
46 % { opacity: 0.5; }
69 % { opacity: 0.25; }
62 % { opacity: 0.67; }
78 % { opacity: 0.67; }
80 % { opacity: 1; }
100 % { opacity: 1; }
}
</ style >
</ head >
< body >
< div id = "text" >
< h1 > Resonant Orbit Calculator</ h1 >
< h2 > For Kerbal Space Program<span> </ span ></ h2 >
< p >
Calculate the resonant orbit needed for a carrier craft to inject craft it carries, like satellites, into equidistant positions of a shared circular orbit.This is useful for setting up things like < a href = "https://wiki.kerbalspaceprogram.com/wiki/CommNet" > CommNet </ a > constellations.The “Injection Δv” value is the delta - v required to move from the resonant orbit to the final(circular) orbit.
</ p >
</ div >
< section >
< form id = "parameters" >
< h3 > Parameters </ h3 >
< ul id = "inputs" >
< li >
< label for= "systlist" > System </ label > < span >
< select id = "systlist" ></ select >
</ span ></ li >
< li >< label for= "bodylist" > Celestial body </ label > < span >
< select id = "bodylist" autofocus ></ select >
</ span ></ li >
< li >< label for= "satellites" > Number of satellites </ label > < span >< input type = "number" id = "satellites" size = "1" step = "1" min = "1" value = "3" ></ span ></ li >
< li >< label for= "altitude" > Orbital altitude </ label > < span >< input type = "text" id = "altitude" size = "12" > m </ span ></ li >
< li >< label > Orbital period </ label > < span >< input type = "text" id = "period" size = "12" disabled ></ span ></ li >
< li class="button"><label>Synchronous orbit</label> <span><input type = "text" id= "synchrorbit" size= "12" disabled></span><b id = "setsync" >⌾</b></li>
<li class="button"><label>Minimum<acronym title="Line-of-Sight"> LOS</acronym> orbit</label> <span><input type = "text" id= "losorbit" size= "12" disabled></span><b id = "setmin" >⌾</b></li>
<li><label for="flipLOS">Show<acronym title="Line-of-Sight"> LOS</acronym> lines</label> <span><input type = "checkbox" id= "flipLOS" ></ span ></ li >
< li >< label for="flipOcc">Occlusion modifiers</label> <span><input type = "checkbox" id= "flipOcc" >
< label for="atmOcclusion"><span>Atm.</span><input type = "number" id= "atmOcclusion" size= "1" min= "0" max= "1.1" step= "0.01" value= "0.75" ></ label >
< label for="vacOcclusion"><span>Vac.</span><input type = "number" id= "vacOcclusion" size= "1" min= "0" max= "1.1" step= "0.01" value= "0.9" ></ label >
</ span ></ li >
</ ul >
< h3 > Resonant orbit</h3>
<ul id = "outputs" >
< li >< label for="fliporbit">Dive orbit</label> <span><input type = "checkbox" id= "fliporbit" ></ span ></ li >
< li >< label > Orbital Period</label> <span><input type = "text" id= "carrierT" size= "12" disabled></span></span></li>
<li><label>Apoapsis</label> <span><input type = "text" id= "carrierAp" size= "12" disabled></span></span></li>
<li><label>Periapsis</label> <span><input type = "text" id= "carrierPe" size= "12" disabled></span></span></li>
<li><label>Injection Δv</label> <span><input type = "text" id= "burnDV" size= "10" disabled></span></span></li>
</ul>
<div id = "debug" ></ div >
</ form >
< div id= "schematic" >
< header ></ header >
< svg viewBox= "0 0 1000 1000" xmlns= "http://www.w3.org/2000/svg" id= "chart" >
< circle cx= "50%" cy= "50%" r= "0" fill= "#FFF" stroke= "#CCC" stroke-dasharray= "15,15" stroke-width= "2" id= "bodySOI" />
< path d= "" fill= "none" stroke-width= "0" stroke= "red" id= "bodySOIlabel" />
< text text-anchor= "middle" font-size= "24" fill= "#888" >
< textpath xlink:href= "#lineofsightlabel" startOffset= "50%" id= "setLOS" > Minimum LOS orbit <tspan id = "msa" ></ tspan > m </ textpath >
</ text >
< text text-anchor= "middle" font-size= "24" fill= "#888" >
< textpath xlink:href= "#geosynclabel" startOffset= "50%" id= "setGeo" > Synchronous orbit<tspan id="syncm"></tspan>m</textpath>
</text>
<text text-anchor= "middle" font-size= "24" fill= "#888" >
< textpath xlink:href= "#bodySOIlabel" startOffset= "50%" > Sphere of Influence <tspan id = "SOId" ></ tspan > m </ textpath >
</ text >
< circle cx= "50%" cy= "50%" r= "0" fill= "#0001" id= "atmosphere" />
< circle cx= "50%" cy= "50%" r= "0" fill= "none" stroke= "#999" stroke-width= "2" stroke-dasharray= "10,10" id= "lineofsight" />
< path d= "" fill= "none" stroke-width= "0" stroke= "red" id= "lineofsightlabel" />
< circle cx= "50%" cy= "50%" r= "0" fill= "none" stroke= "#999" stroke-width= "2" stroke-dasharray= "10,10" id= "geosync" />
< path d= "" fill= "none" stroke-width= "0" stroke= "red" id= "geosynclabel" />
< circle cx= "50%" cy= "50%" r= "0" fill= "none" stroke= "goldenrod" stroke-width= "1.5" id= "satelliteorbit" />
< path d= "" fill= "none" stroke-width= "2" stroke= "green" id= "carrierorbit" />
< circle cx= "50%" cy= "-100" r= "10" fill= "tan" id= "launchpoint" />
< circle cx= "50%" cy= "50%" r= "0" fill= "#666" id= "body" />
< path d= "" fill= "none" stroke-width= "3" stroke= "#0C0" opacity= "0.5" id= "constellation" />
</ svg >
</ div >
</ section >
< footer >
< p > Provided by<a href="https://meyerweb.com/"> Eric Meyer</a> under the<a href="https://choosealicense.com/licenses/mit/"> MIT License</a>.See source for terms and details.</p>
<p>Originally released 2017-02-04 • v1.4 released 2018-01-10</p>
<p><a href = "https://forum.kerbalspaceprogram.com/index.php?/topic/156018-resonant-orbit-calculator/" > KSP Forum thread</a></p>
</footer>
</body>
<script type = "text/javascript" src= "systems.js" ></ script >
< script type= "text/javascript" >
var body = { };
function bodydef(t)
{
this.color = t.color;
this.eqr = t.eqr;
this.mass = t.mass;
this.rot = t.day;
this.atm = t.atm;
this.SOI = t.SOI;
}
Object.defineProperties(bodydef.prototype, {
"GM": {get: function()
{
return this.mass * 6.67408E-11;
}},
"geoSMA": { get: function()
{
if (this.rot) return Math.round(Math.pow(((this.GM * Math.pow(this.rot, 2)) / 39.4784176), 1 / 3));
else return false;
}},
"geoAlt": { get: function()
{
return this.geoSMA - this.eqr;
}},
"SOIAlt": { get: function()
{
return this.SOI - this.eqr;
}},
});
function orbitdef(Ap, Pe, body)
{
this.Ap = Ap;
this.Pe = Pe;
this.body = body;
}
Object.defineProperties(orbitdef.prototype, {
"GM": { get: function() { return this.body.GM; }},
"eqr": { get: function() { return this.body.eqr; }},
"MA": { get: function() { return this.Ap + this.Pe + 2 * this.eqr; }},
"SMA": { get: function() { return this.MA / 2; }},
"ma": { get: function() { return this.MA * Math.sqrt(1 - (Math.pow(this.e, 2))); }},
"sma": { get: function() { return this.ma / 2; }},
"ApR": { get: function() { return this.Ap + this.eqr; }},
"PeR": { get: function() { return this.Pe + this.eqr; }},
"PeV": { get: function() { return Math.sqrt((2 * this.ApR * this.GM) / (this.MA * this.PeR)); }},
"ApV": { get: function() { return Math.sqrt((2 * this.PeR * this.GM) / (this.MA * this.ApR)); }},
"e": { get: function() { return ((this.PeR * Math.pow(this.PeV, 2)) / this.GM) - 1; }},
"F": { get: function() { return Math.sqrt(Math.pow(this.SMA, 2) - Math.pow(this.sma, 2)); }},
"T": { get: function() { return 2 * Math.PI * Math.sqrt(Math.pow(this.SMA, 3) / this.GM); }},
"op": { get: function() { return this.T / 3600; }},
"oph": { get: function()
{
var hours = Math.floor(this.op);
var min = Math.floor((this.op - hours) * 60);
var sec = Math.round(10 * (this.op - hours - min / 60) * 3600) / 10;
var time = hours + "h:" + min + "m:" + sec + "s";
return time;
}},
"newMAfromT": {get: function(newT) { return 2 * Math.cbrt((this.GM * Math.pow(newT, 2)) / 39.4784176); }},
// 39.4784176 = 4π^2
"setAp": { set: function(alt) { this.Ap = alt; }},
"setPe": { set: function(alt) { this.Pe = alt; }},
"modifyAp": { set: function(newMA) { this.setAp = this.Ap + (newMA - this.MA); }},
"modifyPe": { set: function(newMA) { this.setPe = this.Pe - (this.MA - newMA); }},
});
function newMAfromT(T, body)
{
return 2 * Math.cbrt((body.GM * Math.pow(T, 2)) / 39.4784176); // 39.4784176 = 4π^2
}
var inputs = {
"systlist": document.getElementById("systlist"),
"bodylist": document.getElementById("bodylist"),
"altitude": document.getElementById("altitude"),
"satellites": document.getElementById("satellites"),
"fliporbit": document.getElementById("fliporbit"),
"flipLOS": document.getElementById("flipLOS"),
"atmOcclusion": document.getElementById("atmOcclusion"),
"vacOcclusion": document.getElementById("vacOcclusion"),
"flipOcc": document.getElementById("flipOcc"),
"setsync": document.getElementById("setsync"),
"setmin": document.getElementById("setmin"),
};
var outputs = {
"period": document.getElementById("period"),
"synchrorbit": document.getElementById("synchrorbit"),
"losorbit": document.getElementById("losorbit"),
"carrierAp": document.getElementById("carrierAp"),
"carrierPe": document.getElementById("carrierPe"),
"carrierT": document.getElementById("carrierT"),
"burnDV": document.getElementById("burnDV"),
"sorbit": document.getElementById("satelliteorbit"),
"corbit": document.getElementById("carrierorbit"),
"chart": document.getElementById("chart"),
};
var chart = {
"body": document.getElementById("body"),
"bodySOI": document.getElementById("bodySOI"),
"bodySOIlabel": document.getElementById("bodySOIlabel"),
"SOId": document.getElementById("SOId"),
"geosync": document.getElementById("geosync"),
"geosynclabel": document.getElementById("geosynclabel"),
"syncm": document.getElementById("syncm"),
"lineofsight": document.getElementById("lineofsight"),
"lineofsightlabel": document.getElementById("lineofsightlabel"),
"msa": document.getElementById("msa"),
"atmosphere": document.getElementById("atmosphere"),
"satellite": document.getElementById("satelliteorbit"),
"carrier": document.getElementById("carrierorbit"),
"launchpoint": document.getElementById("launchpoint"),
"constellation": document.getElementById("constellation"),
}
// ===================== start coding! ==========================
function setup()
{
systemlist();
inputs.systlist.addEventListener("change", newsystem, false);
inputs.bodylist.addEventListener("change", update, false);
inputs.altitude.addEventListener("change", update, false);
inputs.satellites.addEventListener("change", update, false);
inputs.fliporbit.addEventListener("change", update, false);
inputs.flipLOS.addEventListener("change", update, false);
inputs.vacOcclusion.addEventListener("change", update, false);
inputs.atmOcclusion.addEventListener("change", update, false);
inputs.flipOcc.addEventListener("change", update, false);
inputs.setsync.addEventListener("click", function(){
setAlt("sync");
},false);
inputs.setmin.addEventListener("click", function(){
setAlt("los");
},false);
document.querySelector("#setGeo").addEventListener("click", function(){
setAlt("sync");
},false);
document.querySelector("#setLOS").addEventListener("click", function(){
setAlt("los");
},false);
}
function setAlt(type)
{
if (type == "sync")
{
if (outputs.synchrorbit.value != "n/a")
{
inputs.altitude.value = Number.parseFloat(body.geoAlt);
}
}
if (type == "los")
{
if (outputs.losorbit.value != "n/a")
{
inputs.altitude.value = Number.parseFloat(Math.round(minLOSCalc(body) * 10) / 10);
}
}
update();
}
function systemlist()
{
var slist = inputs.systlist;
while (slist.firstChild)
{
slist.removeChild(slist.firstChild);
}
for (system in systems)
{
var opt = document.createElement('option');
opt.value = system;
opt.textContent = system;
if (decodeURIComponent(window.location.hash) == "#" + system)
{
opt.setAttribute("selected", true);
}
slist.appendChild(opt);
}
newsystem();
}
function newsystem()
{
var blist = inputs.bodylist;
while (blist.firstChild)
{
blist.removeChild(blist.firstChild);
}
var syst = systems[inputs.systlist.value];
for (t in syst)
{
var opt = document.createElement('option');
opt.value = t;
opt.textContent = t;
if (syst[t].default == true) {
opt.setAttribute("selected", true);
}
blist.appendChild(opt);
}
update();
}
function update()
{
var system = inputs.systlist.value;
if (system == "KSP Stock")
{
document.querySelector('h2 span').textContent = "";
history.pushState("", document.title, window.location.pathname + window.location.search);
}
else
{
document.querySelector('h2 span').textContent = " – " + system;
window.location.hash = "#" + encodeURIComponent(system);
}
body = new bodydef(systems[system][inputs.bodylist.value]);
var sataltitude = parseFloat(inputs.altitude.value);
if (sataltitude > body.SOIAlt)
{
outputs.period.setAttribute("disabled", "true");
}
if (body.geoAlt > 0 && body.geoSMA < body.SOI)
{
outputs.synchrorbit.value = body.geoAlt.toLocaleString() + " m";
}
else
{
outputs.synchrorbit.value = "n/a";
}
var minLOS = minLOSCalc(body);
if (minLOS < body.SOIAlt && minLOS > 0)
{
outputs.losorbit.value = (Math.round(minLOS * 10) / 10).toLocaleString() + " m";
if (minLOS < body.atm) outputs.losorbit.classList.add("warning");
else outputs.losorbit.classList.remove("warning");
if (sataltitude * 1.01 < minLOS)
{
chart.constellation.classList.add("warning");
chart.constellation.setAttribute("stroke-dasharray", "7,12,15,2,5,3,9,11");
}
else
{
chart.constellation.classList.remove("warning");
chart.constellation.setAttribute("stroke-dasharray", "");
}
}
else
{
outputs.losorbit.value = "n/a";
}
var satcount = parseInt(inputs.satellites.value);
var satratio = ((satcount + 1) / satcount);
var satelliteorbit = new orbitdef(sataltitude, sataltitude, body);
var carrierorbit = new orbitdef(sataltitude, sataltitude, body);
if (satcount && sataltitude)
{
carrierorbit.modifyAp = newMAfromT(satelliteorbit.T * satratio, body);
if (carrierorbit.Ap > body.SOIAlt || inputs.fliporbit.checked == true) {
satratio = ((satcount - 1) / satcount);
carrierorbit = new orbitdef(sataltitude, sataltitude, body);
carrierorbit.modifyPe = newMAfromT(satelliteorbit.T * satratio, body);
}
outputs.period.value = satelliteorbit.oph;
if (carrierorbit.Ap) outputs.carrierAp.value = (Math.round(carrierorbit.Ap * 10) / 10).toLocaleString() + " m";
if (carrierorbit.Ap < body.atm || carrierorbit.Ap < 0) outputs.carrierAp.classList.add("warning");
else outputs.carrierAp.classList.remove("warning");
if (carrierorbit.Pe) outputs.carrierPe.value = (Math.round(carrierorbit.Pe * 10) / 10).toLocaleString() + " m";
if (carrierorbit.Pe < body.atm) outputs.carrierPe.classList.add("warning");
else outputs.carrierPe.classList.remove("warning");
if (carrierorbit.Pe <= 0) outputs.carrierPe.classList.add("urgent");
else outputs.carrierPe.classList.remove("urgent");
outputs.carrierT.value = carrierorbit.oph;
outputs.burnDV.value = burnCalc(satelliteorbit, carrierorbit, body) + " m/s";
}
if (outputs.period.value == "")
{
document.querySelector("#schematic > header").textContent = '';
}
else
{
var string = inputs.bodylist.value;
string += " (" + inputs.systlist.value + ") ";
string += inputs.satellites.value + "-satellite constellation<br>";
string += "Ap " + outputs.carrierAp.value;
string += " Pe " + outputs.carrierPe.value;
string += " Δv " + outputs.burnDV.value;
document.querySelector("#schematic > header").innerHTML = string;
}
drawchart(satelliteorbit, carrierorbit, body);
}
function burnCalc(s, c, b)
{
var sta = 0;
var cta = 0;
if (c.Ap == s.Ap) cta = 180;
var sr = s.SMA * (1 - Math.pow(s.e, 2)) / (1 + (s.e * Math.cos(sta)));
var sdv = Math.sqrt(b.GM * ((2 / sr) - (1 / s.SMA)));
var cr = c.SMA * (1 - Math.pow(c.e, 2)) / (1 + (c.e * Math.cos(cta)));
var cdv = Math.sqrt(b.GM * ((2 / sr) - (1 / c.SMA)));
return Math.round(100 * Math.abs(sdv - cdv)) / 100;
}
function minLOSCalc(body)
{
var sat = inputs.satellites.value;
if (sat) return (body.eqr * occmod()) / (Math.cos(0.5 * (2 * Math.PI / sat))) - body.eqr;
}
function occmod()
{
if (document.querySelector("#flipOcc").checked == false) return 1;
if (body.atm > 0)
{
return parseFloat(inputs.atmOcclusion.value);
}
else
{
return parseFloat(inputs.vacOcclusion.value);
}
}
function drawchart(s, c, b)
{
var maxMA = Math.max(s.MA, c.MA);
if (!maxMA) maxMA = 3 * b.eqr;
var coordkm = (1000 / maxMA) / 1.5;
var view = 1000;
var mid = view / 2;
chart.body.setAttribute("r", b.eqr * coordkm);
if (b.color != "")
{
chart.body.setAttribute("fill", b.color);
}
else
{
chart.body.setAttribute("fill", "#666");
}
if (b.atm != 0)
{
chart.atmosphere.setAttribute("r", (b.eqr + b.atm) * coordkm);
}
else
{
chart.atmosphere.setAttribute("r", 0);
}
var SOIr = b.SOI * coordkm;
if (SOIr > 10000) SOIr = 10000;
chart.bodySOI.setAttribute("r", SOIr);
chart.bodySOIlabel.setAttribute("d", describeArc(mid, mid, (b.SOI * coordkm) + 7, 90, 270, 1));
chart.SOId.innerHTML = Math.round(b.SOIAlt).toLocaleString();
if (body.geoAlt < body.SOI)
{
chart.geosync.setAttribute("r", (b.geoSMA * coordkm));
if ((b.geoSMA * coordkm) > 60)
{
chart.geosynclabel.setAttribute("d", describeArc(mid, mid, (b.geoSMA * coordkm) + 27, 60, 300));
chart.syncm.innerHTML = (Math.round(b.geoAlt * 10) / 10).toLocaleString();
}
else
{
chart.geosynclabel.setAttribute("d", "M 0 0");
}
}
else
{
chart.geosynclabel.setAttribute("d", "M 0 0");
chart.geosync.setAttribute("r", "0");
}
chart.satellite.setAttribute("r", s.SMA * coordkm);
if (s.Ap < b.atm) chart.satellite.classList.add("warning");
else chart.satellite.classList.remove("warning");
if (c.Pe < b.atm) chart.carrier.classList.add("warning");
else chart.carrier.classList.remove("warning");
chart.carrier.setAttribute("d", "M " + mid + " " + ((view / 2) - s.SMA * coordkm) +
" a " + (c.sma * coordkm) + "," + (c.SMA * coordkm) + " 0 1,0 1,0");
var sats = Number.parseInt(inputs.satellites.value);
if (sats >= 3 && flipLOS.checked == true) {
var sepang = (2 * Math.PI) / sats;
var dString = "";
var half = Math.round(sats / 1.9);
for (var i = 0; i <= sats; i++)
{
var curang = i * sepang;
var xc = mid + Math.sin(curang) * s.SMA * coordkm;
var yc = mid - Math.cos(curang) * s.SMA * coordkm;
if (i > 0) { dString += " L "; } else { dString += " M "; }
dString += xc + " " + yc;
for (var j = 0; j <= half; j++)
{
var checkpos = (i + j) * sepang;
var checkang = checkpos - curang;
var h = Math.cos(0.5 * checkang) * s.SMA;
if (h * 1.001 >= b.eqr)
{
var cxc = mid + Math.sin(checkpos) * s.SMA * coordkm;
var cyc = mid - Math.cos(checkpos) * s.SMA * coordkm;
dString += " L " + cxc + " " + cyc;
dString += " M " + xc + " " + yc;
}
}
if (i > 0 && i < sats)
{
for (var j = 0; j <= sats; j++)
{
var ix = xc + Math.sin(j * sepang) * 7.5;
var iy = yc + Math.cos(j * sepang) * 7.5;
dString += " L " + ix + " " + iy;
}
dString += " M " + xc + " " + yc;
}
}
chart.constellation.setAttribute("d", dString);
} else {
chart.constellation.setAttribute("d", "M 0 0");
}
var minLOS = minLOSCalc(b);
var rad = Math.round(((b.eqr + minLOS)) * coordkm);
if (sats >= 3 && (minLOS * 10 >= s.Ap || isNaN(s.Ap)) && rad > 60)
{
chart.lineofsight.setAttribute("r", rad);
chart.lineofsightlabel.setAttribute("d", describeArc(mid, mid, rad + 27, 60, 300));
chart.msa.innerHTML = (Math.round(minLOS * 10) / 10).toLocaleString();
}
else
{
chart.lineofsight.setAttribute("r", 0);
chart.lineofsightlabel.setAttribute("d", "M 0 0");
}
if (!c.e)
{
chart.launchpoint.setAttribute("cy", -1000);
}
else
{
chart.launchpoint.setAttribute("cy", (view / 2) - s.SMA * coordkm);
}
}
function debug(str)
{
var output = document.getElementById("debug");
output.innerHTML += str + "<br>";
}
// Next two functions courtesy http://stackoverflow.com/a/18473154
function polarToCartesian(centerX, centerY, radius, angleInDegrees)
{
var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians))
};
}
function describeArc(x, y, radius, startAngle, endAngle, flip)
{
if (!flip) var flip = 0;
var start = polarToCartesian(x, y, radius, endAngle);
var end = polarToCartesian(x, y, radius, startAngle);
var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
var d = [
"M", start.x, start.y,
"A", radius, radius, 0, largeArcFlag, flip, end.x, end.y
].join(" ");
return d;
}
setup();
update();
</ script >
</ html >
#endif