-
Notifications
You must be signed in to change notification settings - Fork 0
/
orbitutility.ks
61 lines (51 loc) · 1.42 KB
/
orbitutility.ks
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
set DegToRad to constant():PI / 180.
set RadToDeg to 180 / constant():PI.
function cosr {
parameter x.
return cos(RadToDeg * x).
}
function sinr {
parameter x.
return sin(RadToDeg * x).
}
function acosr {
parameter x.
return DegToRad * arccos(x).
}
function GetOrbitNormal {
parameter orbitable.
return vcrs(orbitable:up:forevector, orbitable:prograde:forevector):normalized.
}
function EccAnomR {
parameter ecc, trueAnom.
return acosr((ecc + cosr(trueAnom)) / (1 + ecc * cosr(trueAnom))).
}
function MeanAnomR {
parameter ecc, eccAnom.
return eccAnom - ecc * sinr(eccAnom).
}
function MeanMotionR {
parameter orbit.
return sqrt(orbit:body:mu / (orbit:semimajoraxis * orbit:semimajoraxis * orbit:semimajoraxis))
}
function TimeOfTrueAnomaly {
parameter orbit.
parameter trueAnomaly.
return (MeanAnomR(orbit:eccentricity, EccAnomR(orbit:eccentricity, DegToRad * trueAnomaly)) - (DegToRad * orbit:meananomalyatepoch)) / MeanMotionR(orbit).
}
function TimeToAscendingNode {
parameter orbitable.
set ttan to TimeOfTrueAnomaly(orbitable, 360 - orbitable:obt:argumentofperiapsis) - time:seconds.
if ttan < 0 {
set ttan to ttan + orbitable:obt:period.
}
return ttan.
}
function TimeToDescendingNode {
parameter orbitable.
set ttdn to TimeOfTrueAnomaly(orbitable, 180 - orbitable:obt:argumentofperiapsis) - time:seconds.
if ttdn < 0 {
set ttdn to ttdn + orbitable:obt:period.
}
return ttdn.
}