-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhullvizDEMO.m
133 lines (93 loc) · 2.63 KB
/
hullvizDEMO.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
clear all
close all
clc
load hvdemodata
idx = idxfull;
clear idxfull
coord = coordfull;
clear coordfull
clus = clusters;
clusters(:,1) = clus(:,2);
clusters(:,2) = clus(:,1);
numclusters = size(clusters,1);
%Initialize now so you can call it in a conditional statement later
vecmat = [];
%%%First find the convexhull so you can draw it
for k = 1:numclusters
%Clear to avoid mismatch later
points = [];
index = find(idx == k);
points(:,1) = coord(index,1);
points(:,2) = coord(index,2);
%%TODO PROBLEMS IF YOU DON'T HAVE THREE UNIQUE <X,Y> IN POINTS, CAN'T
%%MAKE A CONVEX HULL
m = size(points,1);
dontcheck = zeros(size(points,1),1);
unique = m;
for i = 1:m
if dontcheck(i) == 1
continue
end
[a, ~] = find(points == points(i,1));
[b, ~] = find(points == points(i,2));
c = intersect(a,b);
dontcheck(c) = 1;
unique = unique - (length(c) - 1);
end
if unique < 3
vec(size(vecmat,1),2) = NaN;
vecmat = [vecmat vec];
continue
end
%%Have to do add a bunch of NaN's because you can't append a column of
%%different size.
hull = convhull(points(:,1), points(:,2));
%Have to reinitialize because of size problems
vec = [];
vec(:,1) = points(hull,1);
vec(:,2) = points(hull,2);
%%Now aggregate
if k ~= 1 && size(vecmat,1) < size(vec,1)
vecmat((size(vecmat,1) + 1):size(vec,1), :) = NaN;
end
if k ~= 1 && size(vecmat,1) > size(vec,1)
vec((size(vec,1) + 1):size(vecmat,1), :) = NaN;
end
vecmat = [vecmat vec];
end
%%%PLOT
bg = imread('purduemap.png');
% axes for image
min_y = 40.41678;
min_x = -86.930501;
max_y = 40.438766;
max_x = -86.905546;
% disp image
figure;
imagesc([min_x max_x], [min_y max_y], flipdim(bg,1));
hold on
% Plot the GPS locations and clusters
plot(coord(:,1),coord(:,2),'.')
hold on
%%% TODO label the clusters
plot(clusters(:,1),clusters(:,2),'r*')
title(['GPS location data and ' , num2str(numclusters) , ' clusters'])
xlabel('lat')
ylabel('long')
hold on
% Plot the outside of each cluster
k = 1;
index = ~isnan(vecmat(:,k:k+1));
vectemp = vecmat(1:sum(sum(index,1))/2,k:k+1);
plot(vectemp(:,k),vectemp(:, k+1),'g','linewidth',2)
hold on
% Already did the first cluster
for k = 2:numclusters
index = ~isnan(vecmat(:,2*k - 1:2*k));
vectemp = vecmat(1:sum(sum(index,1))/2,2*k - 1:2*k);
plot(vectemp(:,1),vectemp(:,2),'g','linewidth',2)
hold on
end
plot(clusters(:,1),clusters(:,2),'r*')
% flip
set(gca,'ydir','normal');