-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_inc_equ.ks
40 lines (33 loc) · 1.28 KB
/
node_inc_equ.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
// Match inclinations with target by planning a burn at the ascending or
// descending node, whichever comes first.
// Desired orbital inclination
parameter target_inclination.
local position is ship:position-ship:body:position.
local velocity is ship:velocity:orbit.
local ang_vel is 4 * ship:obt:inclination / ship:obt:period.
local equatorial_position is V(position:x, 0, position:z).
local angle_to_equator is vang(position,equatorial_position).
if position:y > 0 {
if velocity:y > 0 {
// above & traveling away from equator; need to rise to inc, then fall back to 0
set angle_to_equator to 2 * ship:obt:inclination - abs(angle_to_equator).
}
} else {
if velocity:y < 0 {
// below & traveling away from the equator; need to fall to inc, then rise back to 0
set angle_to_equator to 2 * ship:obt:inclination - abs(angle_to_equator).
}
}
local frac is (angle_to_equator / (4 * ship:obt:inclination)).
local dt is frac * ship:obt:period.
local t is time + dt.
local relative_inclination is abs(ship:obt:inclination - target_inclination).
local v is velocityat(ship, T):orbit.
local dv is 2 * v:mag * sin(relative_inclination / 2).
if v:y > 0 {
// burn anti-normal at ascending node
add node(T:seconds, 0, -dv, 0).
} else {
// burn normal at descending node
add node(T:seconds, 0, dv, 0).
}