-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotRocket.m
90 lines (75 loc) · 2.96 KB
/
plotRocket.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
%% plotRocket
% plots rocket consisting of the rocket body, top, fuel tank and flame
%
% inputs: axes_handle... axes handle to plot where it is shown
% vertical_position... vertical position of the rocket [m]
% m_Fuel... mass of current fuel [kg]
% Bremse... brakes on or off [true/false]
function plotRocket(axes_handle, vertical_position, m_Fuel, Bremse)
%% rocket geometrical parameters
rocket_width = 10;
top_height = 20;
body_height = 60;
%% generate top shape from spline
x = [0, top_height];
y = [0, rocket_width/2, 0, -(rocket_width)/top_height];
spl_top = spline(x,y);
x_val = linspace(0, top_height, 100);
rot90_left = [0, -1; 1, 0];
top_left = rot90_left*[x_val; ppval(spl_top, x_val)];
top_right = rot90_left*[x_val; -ppval(spl_top, x_val)];
x_top_left = top_left(1,:);
y_top_left = top_left(2,:) + body_height;
x_top_right = top_right(1,:);
y_top_right = top_right(2,:) + body_height;
%% generate flame shape from spline
x = [0, top_height];
y = [0.5, 0.4*rocket_width, 0, -(rocket_width)/top_height];
spl_flame = spline(x,y);
x_val = linspace(0, max(x), 100);
rot90_right = [0, 1; -1, 0];
flame_left = rot90_right*[x_val; ppval(spl_flame, x_val)];
flame_right = rot90_right*[x_val; -ppval(spl_flame, x_val)];
x_flame_left = flame_left(1,:);
y_flame_left = flame_left(2,:);
x_flame_right = flame_right(1,:);
y_flame_right = flame_left(2,:);
%% animate objects
% clear previous plot
delete(findobj('Tag','rocket'))
% shorter variable name for function
z = vertical_position;
% animate rocket
rocket_x = [x_top_left, fliplr(x_top_right), -rocket_width/2*[-1, -1, 1, 1]];
rocket_z = [y_top_left, fliplr(y_top_right), [body_height, 0, 0, body_height]] + z;
% animate fuel tank
tank_x = rocket_width*0.4*[-1, -1, 1, 1];
tank_y = z + body_height*(0.1 + 0.8*[0, 1, 1, 0]);
fuel_x = rocket_width*0.4*[-1, -1, 1, 1];
fuel_y = z + body_height*(0.1 + 0.8*[0, 1, 1, 0])*m_Fuel/8200;
% animate flame
flame_x = [x_flame_left, fliplr(x_flame_right)];
flame_y = z + [y_flame_left, fliplr(y_flame_right)];
fill(axes_handle, rocket_x, rocket_z, [0.8, 0.8, 0.8], 'Tag','rocket')
fill(axes_handle, tank_x, tank_y, 'white', 'Tag', 'rocket');
fill(axes_handle, fuel_x, fuel_y, [0.9294, 0.6941, 0.1255], 'Tag', 'rocket');
% plot flame only when Bremse is active
if Bremse
fill(axes_handle, flame_x, flame_y, [1, 1, 0.0667], 'Tag', 'rocket');
end
% plot moon surface
rectangle('Position',[-50,-100,100,100],'FaceColor',[0.9 0.9 0.9])
% set aspect ratios to be equal
daspect(axes_handle, [1,1,1]);
% as soon as the ground is visible, the axis limits are no longer moved
% with the rocket, instead it is fixed relative to the moon surface
limits_moving = z + [-1, 1]*(body_height + top_height)*1.2;
limits_fixed = [0, 2]*(body_height + top_height)*1.2;
if limits_moving(1)> -20
axes_handle.YLim = limits_moving;
else
axes_handle.YLim = limits_fixed-20;
end
% background color set to dark blue to imitate space
axes_handle.Color = [0, 0.4471, 0.7412];
end