Skip to content

Commit 7aeeda9

Browse files
committed
vector animation plots
1 parent c054698 commit 7aeeda9

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

postprocessing/plotting/imseq_vecex.m

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
function imseq_vecex(y, cfg, nfmax, view_dim)
2+
% plot for vector export, based on maximum # of vector lines and frames
3+
% Expect y to be (6, N)
4+
% no need to interpolate vectors unless you have VERY big skips in L
5+
% Reference: https://www.mathworks.com/help/matlab/ref/getframe.html
6+
% Splits by orbit number
7+
8+
[~, ~, ~, ~, ~, L] = unpack_mee(y);
9+
10+
if nargin < 3
11+
nfmax = 20;
12+
view_dim = 3;
13+
end
14+
15+
%% Data processing
16+
ind_orbits = find(diff(mod(L, 2*pi)) < 0);
17+
num_orbits = length(ind_orbits);
18+
19+
%% Initial plot stuff
20+
L_sample = linspace(0, 2*pi, 60);
21+
plot_sphere(0, 0, 0, 6378e3, [0.3010, 0.7450, 0.9330]);
22+
hold on
23+
24+
cm = colormap("turbo");
25+
th = title(sprintf("Orbit 1 of %d", num_orbits));
26+
27+
% plot initial trace
28+
cart_sample = mee2cartesian([repmat(y(1:5, 1), 1, numel(L_sample)); L_sample]);
29+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(1, :), "DisplayName", "Initial Orbit", "LineWidth", 1, "LineStyle", "--");
30+
31+
% plot main orbit
32+
main_orbit = plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", "black", "DisplayName", "Current Orbit", "LineWidth", 1);
33+
34+
% plot final trace
35+
cart_sample = mee2cartesian([repmat(y(1:5, end), 1, numel(L_sample)); L_sample]);
36+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(end, :), "DisplayName", "Final Orbit", "LineWidth", 1, "LineStyle", "--");
37+
38+
% colorbar
39+
colorbar;
40+
clim([1,num_orbits]);
41+
42+
axis equal
43+
view(view_dim)
44+
45+
%% Initialize path
46+
mkdir("anim")
47+
mkdir("anim", cfg.casename)
48+
49+
%% Animation
50+
% spacing; never plot more than 20 frames
51+
stride = max(1, ceil(num_orbits/nfmax));
52+
53+
% ensure we always plot the last orbit
54+
ii = 1; % counter
55+
for j = [1:stride:num_orbits, num_orbits]
56+
% Update plots
57+
idx = ind_orbits(j);
58+
cart_sample = mee2cartesian([repmat(y(1:5, idx), 1, numel(L_sample)); L_sample]);
59+
main_orbit.XData = cart_sample(1, :);
60+
main_orbit.YData = cart_sample(2, :);
61+
main_orbit.ZData = cart_sample(3, :);
62+
63+
% Add shadow of previous orbits
64+
colour_idx = ceil(j/num_orbits*length(cm));
65+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "LineWidth", 1);
66+
67+
th.String = sprintf("Orbit %d of %d", j, num_orbits);
68+
69+
% Draw and get frame
70+
drawnow
71+
72+
% https://www.mathworks.com/matlabcentral/answers/1615265-physical-size-of-exportgraphics
73+
hf = gcf;
74+
set(hf, 'Units', 'centimeters',...
75+
'OuterPosition', [4 4 12 12])
76+
exportgraphics(hf, fullfile("anim", cfg.casename, sprintf("anim-%d.pdf", ii)), 'ContentType', 'vector')
77+
ii = ii + 1; % JANK but works
78+
end
79+
end

0 commit comments

Comments
 (0)