-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotDetectionRange.m
140 lines (126 loc) · 5.01 KB
/
plotDetectionRange.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
% Plotter
ellipsoid_plotter = false;
viewpoints_plotter= true;
tsp_plotter = true;
traj_plotter = true;
overlap_plotter = false;
% Plot the surface
figure(2);
trisurf(gm);
axis equal;
hold on;
scatter3(C(:,1), C(:,2), C(:,3), 50, "o", "r", 'filled'); % Plot medoids
if (viewpoints_plotter)
scatter3(viewpoints(:,1), viewpoints(:,2), viewpoints(:,3), 20, "o", "b", 'filled'); % Plot the viewpoints
scatter3(waypoints(:,1), waypoints(:,2), waypoints(:,3), 50, "o", "m", 'filled');
scatter3(start_point(1), start_point(2), start_point(3), 50, "o", "y", 'filled'); % highlight the starting point
end
legend('Surface', 'Cluster medoids', 'Viewpoints', 'Waypoints', 'Start point');
title('K-Medoids Clustering with Custom Distance Function');
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on;
if (ellipsoid_plotter)
% Plot the ellipses around each centroid
theta = linspace(0, 2*pi, 100);
for i = 1:size(C, 1)
% Centroid location
cx = C(i, 1);
cy = C(i, 2);
cz = C(i, 3);
% Directional information
nx = C(i, 4);
ny = C(i, 5);
nz = C(i, 6);
c_normal = [nx, ny, nz];
% Ellipse in 3D space
[ex, ey, ez] = ellipsoidPoints(cx, cy, cz, rmaj_p_2*1e3, rmaj_p_2*1e3, c_normal);
% Plot the ellipse
plot3(ex, ey, ez, 'r', 'LineWidth', 0.5);
end
end
if strcmp(obj, 'comparison')
hFig = gcf;
hFigCopy = copyobj(hFig, 0);
end
% TSP ploter
if (tsp_plotter && tsp)
switch obj
case 'duration'
hGraph = plot(G,'XData',waypoints(:, 1),'YData',waypoints(:, 2), 'ZData', waypoints(:, 3), 'LineStyle','none','NodeLabel',{}, 'Marker','none', 'LineWidth',3, 'EdgeColor','b');
highlight(hGraph,Gsol,'LineStyle','-');
drawnow;
title('Inspection optimised for mission duration');
case 'battery'
hGraph = plot(G_2,'XData',waypoints(:, 1),'YData',waypoints(:, 2), 'ZData', waypoints(:, 3), 'LineStyle','none','NodeLabel',{}, 'Marker','none', 'LineWidth',3, 'EdgeColor','b');
highlight(hGraph,Gsol_2,'LineStyle','-');
drawnow;
title('Inspection optimised for battery consumption');
case 'comparison'
figure(2);
hold on;
hGraph = plot(G,'XData',waypoints(:, 1),'YData',waypoints(:, 2), 'ZData', waypoints(:, 3), 'LineStyle','none','NodeLabel',{}, 'Marker','none', 'LineWidth',3, 'EdgeColor','b');
highlight(hGraph,Gsol,'LineStyle','-');
drawnow;
title('Inspection optimised for mission duration');
figure(3);
hold on;
hGraph_2 = plot(G_2,'XData',waypoints(:, 1),'YData',waypoints(:, 2), 'ZData', waypoints(:, 3), 'LineStyle','none','NodeLabel',{}, 'Marker','none', 'LineWidth',3, 'EdgeColor','b');
highlight(hGraph_2,Gsol_2,'LineStyle','-');
drawnow;
title('Inspection optimised for battery consumption');
end
end
% Traj plotter
if (traj_plotter && trajGeneration)
switch obj
case 'duration'
plot3(position(:,1),position(:,2),position(:,3));
title('Inspection optimised for mission duration + trajectory');
case 'battery'
plot3(position(:,1),position(:,2),position(:,3))
title('Inspection optimised for battery consumption + trajectory');
case 'comparison'
% Duration
figure(2);
hold on;
plot3(position(:,1),position(:,2),position(:,3))
title('Inspection optimised for mission duration + trajectory');
% Battery
figure(3)
hold on;
plot3(position_2(:,1),position_2(:,2),position_2(:,3))
title('Inspection optimised for battery consumption + trajectory');
end
end
% Overlap plotter
if overlap_calculation
% Disp results
disp(['Overlap: ', num2str(area_overlaped/area_structure * 100), ' %']);
disp([num2str(no_overlap), '% of the polygons are inspected exactly once']);
disp([num2str(overlapped_elmts), '% of the polygons are inspected more than once']);
disp([num2str(overlapped_twice), '% of the polygons are inspected twice']);
disp([num2str(overlapped_thrice), '% of the polygons are inspected thrice']);
end
if (overlap_plotter && overlap_calculation)
% Category labels for the bar plot
categories = {'No Overlap', 'Overlapped Elements', 'Overlapped Twice', 'Overlapped Thrice'};
percentages = [no_overlap, overlapped_elmts, overlapped_twice, overlapped_thrice];
% Create the bar plot
figure(4);
bar(percentages);
% Set the x-tick labels using the category labels
set(gca, 'XTick', 1:numel(categories), 'XTickLabel', categories);
% Add a title and labels to the plot
title('Overlap Analysis');
xlabel('Overlap Status');
ylabel('Percentage (%)');
% Set the y-axis limits to [0, 100] to show percentages clearly
ylim([0 100]);
end
% % Get the handle of the current figure
% hFig = gcf;
%
% % Create a copy of the figure
% hFigCopy = copyobj(hFig, 0);