-
Notifications
You must be signed in to change notification settings - Fork 1
/
HAL_isomatrix_region.m
168 lines (131 loc) · 4.76 KB
/
HAL_isomatrix_region.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function [] = HAL_isomatrix_region(varargin)
labels = {'','',''};
defaultFilename = 'IsoMaTrixGrid.csv';
p = inputParser;
addParameter(p,'Labels',labels);
% validation of user input labels:
errorMsg1 = strcat('Labels error: please provide vector of size=3.');
errorMsg2 = 'Incorrect label formatting (must be cell-array).';
isstringy = @(x) assert(ischar(x),'Filename must be a string');
labelLength = @(x) assert(length(x)==3,errorMsg1);
labelType = @(x) assert(length(x)==3,errorMsg2); % this is incorrect
% read in optional parameters
[nParams] = length(varargin);
for param = 1:1:(nParams/2)
index = (param-1)*2 + 1;
if strcmp(varargin{index}, 'Labels')
labels=varargin{index+1};
labelLength(labels);
labelType(labels);
elseif strcmp(varargin{index}, 'Filename')
defaultFilename=varargin{index+1};
% check if string
isstringy(defaultFilename);
end
end
h = gcf;
figure_number=h.Number;
figure(figure_number); hold on;
% string concatenate filepath:
filepath = strcat('HALMatrixGame/HALMatrix-output/',defaultFilename);
%% read in data
data = dlmread(filepath,',',2,0);
x0 = data(:,1:3);
xF = data(:,4:6);
sims = max(data(:,7))+1;
gridlines = max(data(:,8));
%% create mesh grid
step = 1/gridlines;
x_grid = 0:step:(1);
y_grid = x_grid;
[P,Q] = meshgrid(x_grid,y_grid); % Generate domain.
%% remove irrelevant:
w = P + Q;
out = w > 1;
P(out) = nan;
Q(out) = nan;
% coordinate transformation
y1 = (P./(tan(pi/3)) + (1-P-Q)./(sin(pi/3)))*sin(pi/3);
y2 = P * (1/2)*tan(60*pi/180);
[rows,~] = size(data);
[n,m] = size(P);
Z = zeros(n,m);
Z1 = zeros(n,m);
Z2 = zeros(n,m);
Z3 = zeros(n,m);
N = sum(x0(1,:));
grid_step = N/gridlines;
for row = 1:sims:rows
j = round(x0(row,1)/grid_step) + 1;
i = round(x0(row,2)/grid_step) + 1;
R = xF(row:(row+sims-1),:) - x0(row:(row+sims-1),:);
Z1(i,j) = mean(R(:,1));
Z2(i,j) = mean(R(:,2));
Z3(i,j) = mean(R(:,3));
% mean of the mags, not mag of the means
Mag = sqrt(R(:,1).^2 + R( :,2).^2 + R( :,3).^2);
Z(i,j) = mean(Mag);
% arrow mag:
V = R(:,1); U = (R(:,3)-R(:,2))*cos(pi/3);
angle = atan2(V,U);
end
blue = [0.2188,0.4531,0.6914];
red = [0.7734,0.2188,0.1719];
green = [0.3086,0.6211,0.2227];
blue_red = [229,148,159]/255;
blue_green = [170,229,235]/255;
red_green = [208,184,74]/255;
rainbow = [green;
red_green;
red;
blue_red;
blue;
blue_green];
[n,m] = size(Z);
for i = 1:n
for j = 1:m
if (~isnan(Z(i,j)))
%% test all cases
if ( (Z1(i,j)>=0) && (Z2(i,j)>=0) && (Z3(i,j)>=0) )
Z(i,j) = 1; % 000
elseif ( (Z1(i,j)>=0) && (Z2(i,j)>=0) && (Z3(i,j)<0) )
Z(i,j) = 3; % 001
elseif ( (Z1(i,j)>=0) && (Z2(i,j)<0) && (Z3(i,j)>=0) )
Z(i,j) = 5; % 010
elseif ( (Z1(i,j)>=0) && (Z2(i,j)<0) && (Z3(i,j)<0) )
Z(i,j) = 4; % 011
elseif ( (Z1(i,j)<0) && (Z2(i,j)>=0) && (Z3(i,j)>=0) )
Z(i,j) = 7; % 100
elseif ( (Z1(i,j)<0) && (Z2(i,j)>=0) && (Z3(i,j)<0) )
Z(i,j) = 2; % 101
elseif ( (Z1(i,j)<0) && (Z2(i,j)<0) && (Z3(i,j)>=0) )
Z(i,j) = 6; % 110
elseif ( (Z1(i,j)<0) && (Z2(i,j)<0) && (Z3(i,j)<0) )
Z(i,j) = 8; % 111
else
Z(i,j) = -1;
end
end
end
end
gcf; hold on;
colormap(gca,rainbow);
colorbar;
caxis([1.5,7.5]);
cmapdef = colormap(gca,rainbow) ; %Define Colormap
cmap = cmapdef(1:8:end, :) ; %Find Values of colors corresponding to each point plotted
cbh = colorbar('YTickLabel', {'-, +, -','+, +, -','+, -, -','+, -, +','-, -, +','-, +, +'}) ;
cbh.FontSize = 24;
[~,h]=contourf(y1,y2,Z,100); hold on;
set(h,'LineColor','none');
L = 1;
H = (L/2)*tan(60*pi/180);
d1 = 0.26;
d2 = 0.18;
legend_string = {'($\dot{x}_1, \dot{x}_2, \dot{x}_3$)'};
if ~isempty(labels{1})
legend_string = {strcat('($\dot{x}_',labels{1}, ', \dot{x}_',labels{2}, ', \dot{x}_',labels{3},'$)')};
end
text(L+d1,H+d2,legend_string, 'HorizontalAlignment','center', 'VerticalAlignment','middle', 'fontsize', 18, 'Interpreter','Latex');
add_labels(labels);
end