Joining a set of points inside a buffer to get a polygon.
Mostra commenti meno recenti
I have a set of points which is not in correct order. I need to connect those points to get a closed polygon (The polygon is a plan of the building). I am able to create a buffer around the points which is in the shape of the required polygon. I need to connect points with two conditions. Connect the points to the nearest neighbour so that, the line joining the points should not cross the boundary of the buffer. I have many building samples like this and this is the method which will work for all.
x=[141 188 178 217 229 282 267 307 313 357 372 422 434 365 372 398 411 382 382 233 229 191 185 166 156 183 173 114 97 149 139 139];
y=[109 103 79 76 140 132 64 56 78 72 141 133 180 192 234 228 287 293 315 348 343 348 329 332 270 268 225 240 194 184 108 108];
X=[364.5333 232.1333 397.0667 157.5333 431 421.3333 306.9286 184.3846 357.7333 199.4118 168.6429 179.4737 408.1333 382.4706 150.7333 372.2667 184.8 138.1053 312.1429 108.5333 174.5 195.2667 257.2 99.33333 379.5333 371.8667 329.25 280.7059 267.7143 218.2778];
Y=[192.0267 140.36 228.6267 274.4933 180.4267 133.2933 56.85714 269.3077 69.49333 348.6706 330.8571 80.44211 286.6933 314.5412 182.76 233.36 101.8933 111 77.78571 239.2 226.7857 326.6933 340.5 193.4667 292.96 142.16 327.45 130.5529 64.64286 74.35556];
R = [x' y'];
d = 12;
polyout = polybuffer(R,'lines',d)
figure
%imshow(I2);
hold on
%plot(R(:,1),R(:,2),'r.','MarkerSize',10)
plot(X,Y,'r.', 'MarkerSize', 15)
plot(polyout)
axis equal
hold off

2 Commenti
KSSV
il 30 Apr 2019
Which points you want to join? [X Y] or R?
Nikhil Jose
il 30 Apr 2019
Risposta accettata
Più risposte (1)
KSSV
il 30 Apr 2019
X=[364.5333 232.1333 397.0667 157.5333 431 421.3333 306.9286 184.3846 357.7333 199.4118 168.6429 179.4737 408.1333 382.4706 150.7333 372.2667 184.8 138.1053 312.1429 108.5333 174.5 195.2667 257.2 99.33333 379.5333 371.8667 329.25 280.7059 267.7143 218.2778];
Y=[192.0267 140.36 228.6267 274.4933 180.4267 133.2933 56.85714 269.3077 69.49333 348.6706 330.8571 80.44211 286.6933 314.5412 182.76 233.36 101.8933 111 77.78571 239.2 226.7857 326.6933 340.5 193.4667 292.96 142.16 327.45 130.5529 64.64286 74.35556];
%% Order the points
P = [X' Y'] ;
c = mean(P); % mean/ central point
d = P-c ; % vectors connecting the central point and the given points
th = atan2(d(:,2),d(:,1)); % angle above x axis
[th, idx] = sort(th); % sorting the angles
P = P(idx,:); % sorting the given points
P = [P ; P(1,:)]; % add the first at the end to close the polygon
figure
hold on
plot(X,Y,'b')
plot( P(:,1), P(:,2), 'r');
legend('before sorting','after sorting')
3 Commenti
Nikhil Jose
il 30 Apr 2019
KSSV
il 30 Apr 2019
The buffer must be giving you coordinates of the polygon......with those polygons use inpolygon and check whether point lies inside or outside.
Nikhil Jose
il 30 Apr 2019
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!