-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanimateMission.m
110 lines (87 loc) · 2.86 KB
/
animateMission.m
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
% animateMission.m
%%% TODO
% Change step to numberOfSteps
% Add lag to transit points instead of planets
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function animateMission(N1, N2, T1, T2, startDate, maxDuration, axHandle, dtOption, c3Option)
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%{
This function draws the mission at many time steps.
INPUTS:
N1 - Sequence of departure planets
N2 - Sequence of arrival planets
T1 - Sequence of departure times
T2 - Sequence of arrival times
startDate - Initial date for mission (in struct)
maxDuration - Total duration of the mission
axHandle - Handle for the axes to draw on
OUTPUTS:
REQUIRES:
drawOrbit
Orbit
Planet
%}
% ----------------------------------------------
startTime = centuriesPastJ2000(startDate);
planetIndices = unique([N1 N2]);
numPlanets = length(planetIndices);
planets = (Planet(0));
for body = 1:numPlanets
planets(body) = Planet(planetIndices(body), startTime);
end
phase = 0;
% Animation step in days -- must evenly divide maxDuration
step = 5;
lag = 0 * step;
h = zeros((maxDuration / step) + 1, numPlanets);
hold on
cla(axHandle)
axes(axHandle)
axis equal off
% Plot sun and orbits
plot3(axHandle, 0, 0, 0, 'yo')
for body = 1:max(planetIndices)
drawOrbit(axHandle, body, startTime);
end
drawnow
prevTransitStep = -1;
numTransitSteps = 100;
for day = 0:step:maxDuration
% Check phase
if phase == 0 || day > T2(phase)
phase = phase + 1;
prevTransitStep = -1;
% Initialize transit orbit
if N1(phase) ~= N2(phase)
planetDepart = Planet(N1(phase), startTime + T1(phase) / 36525);
planetArrive = Planet(N2(phase), startTime + T2(phase) / 36525);
[transfer, ~, ~] = Orbit.transferOrbit(planetDepart, planetArrive, T2(phase) - T1(phase), dtOption, c3Option);
end
end
% Plot planets
for body = 1:numPlanets
planet = planets(body);
if planetIndices(body) == N1(phase) && planetIndices(body) == N2(phase)
plot3(axHandle, planet.r(1), planet.r(2), planet.r(3), 'ro');
else
h(day / step + 1, body) = plot3(axHandle, planet.r(1), planet.r(2), planet.r(3), 'ko');
end
if day > lag
if h((day - lag) / step, body)
delete(h((day - lag) / step, body));
end
end
planet.propagateState(step);
end
% Plot transit
phaseDay = day - T1(phase);
phaseLength = T2(phase) - T1(phase);
phaseComplete = phaseDay / phaseLength;
if N1(phase) ~= N2(phase) && fix(numTransitSteps * phaseComplete) > prevTransitStep
prevTransitStep = fix(numTransitSteps * phaseComplete);
transfer = transfer.propagateState(step);
plot3(axHandle, transfer.r(1), transfer.r(2), transfer.r(3), 'bo');
end
drawnow
end
end