-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_plot.m
105 lines (98 loc) · 3.5 KB
/
binary_plot.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
function binary_plot(R0,V0,dt,step,m1,m2)
%% Plot the orbits of two objects orbiting their center of mass.
%
% Jeremy Penn
% 21 October 2017
%
% Revision: 21/10/17
%
% function binary_plot(R0,V0,dt,step,m1,m2)
%
% Purpose: This function plots the trajectories of two objects about
% their common center of mass.
%
% Inputs: o R0 - A 1x3 vector of the initial separation vector
% between m1 and m2.
% o V0 - A 1x3 vector of the initial total velocity vector.
% o dt - The time difference (tf - ti).
% o step - The step size for the calculation
% o m1 - Mass of object 1 in solar mass
% o m2 - Mass of object 2 in solar mass
%
% Requires: binary_trajectory.m
%
%% Calculate the trajectories
[rf1,rf2] = binary_trajectory(R0,V0,m1,m2,dt,step);
%% Plot Orbits
str = input('Readout plot to video?\n','s');
switch str
case 'y'
name = input('Please name output animation\n','s');
con = strcat('~/Documents/matlab/animation/',name);
vid = VideoWriter(con);
open(vid);
set(gcf,'color','black');
whitebg('black');
CoM = ((rf1(1,:) * m1) + (rf2(1,:) * m2)) / (m1 * m2);
scatter3(CoM(1),CoM(2),CoM(3),'xwhite');
hold on
for i = 1:length(rf1)
axis off
grid off
scatter3(rf1(i,1),rf1(i,2),rf1(i,3),'.r');
scatter3(rf2(i,1),rf2(i,2),rf2(i,3),'.g');
frame = getframe(gcf);
writeVideo(vid,frame);
end
hold off;
close(vid);
case 'yes'
name = input('Please name output animation\n','s');
con = strcat('~/Documents/matlab/animation/',name);
vid = VideoWriter(con);
open(vid);
set(gcf,'color','black');
whitebg('black');
CoM = ((rf1(1,:) * m1) + (rf2(1,:) * m2)) / (m1 * m2);
scatter3(CoM(1),CoM(2),CoM(3),'xwhite');
%hold on
for i = 1:length(rf1)
axis off
grid off
scatter3(rf1(i,1),rf1(i,2),rf1(i,3),'.r');
scatter3(rf2(i,1),rf2(i,2),rf2(i,3),'.g');
frame = getframe(gcf);
writeVideo(vid,frame);
end
%hold off;
close(vid);
case 'n'
set(gcf,'color','black');
whitebg('black');
CoM = ((rf1(1,:) * m1) + (rf2(1,:) * m2)) / (m1 * m2);
scatter3(CoM(1),CoM(2),CoM(3),'xwhite');
hold on
for i = 1:length(rf1)
axis off
grid off
scatter3(rf1(i,1),rf1(i,2),rf1(i,3),'.r');
scatter3(rf2(i,1),rf2(i,2),rf2(i,3),'.g');
end
hold off
case 'no'
set(gcf,'color','black');
whitebg('black');
CoM = ((rf1(1,:) * m1) + (rf2(1,:) * m2)) / (m1 * m2);
scatter3(CoM(1),CoM(2),CoM(3),'xwhite');
hold on
for i = 1:length(rf1)
axis off
grid off
scatter3(rf1(i,1),rf1(i,2),rf1(i,3),'.r');
scatter3(rf2(i,1),rf2(i,2),rf2(i,3),'.g');
end
hold off
otherwise
error('Error: Please choose "yes" or "no"')
end
end