Home » Math » Voronoi Diagram, Capitals of Every Country

# Voronoi Diagram, Capitals of Every Country

clear all; clc;close all;

```load CapLatLon
lat = CapLatLon(:,1);
lon = CapLatLon(:,2);
sz = size(lon);
for i =1:sz(1)
if lon(i) <= 0
lon(i) = lon(i)+360;
end
end
fig = figure('Position',[0 0 800 800]);
hold on;
xy = [lon,lat];
ind =1;
[v,c] = voronoin(xy);
figure(1);
col = colormap(pink);
for i = 1:length(c)
if ind >= 24
ind = 1;
end
p = patch(v(c{i},1),v(c{i},2), col(35+ind,:) ); % use color i.
set(p,'EdgeColor','w')
ind = ind + 4;
end```
`Map Configuration`
```xwidth = 820;
ywidth = 420;
hFig = figure(1);
set(gcf,'PaperPositionMode','auto')
set(hFig, 'Position', [100 100 xwidth ywidth])
hold on;
axis([0 360 -90 90]);
contour(0:359,-90:89,topo,[0 0],'.k')
axis equal
box on
set(gca,'XLim',[0 360],'YLim',[-90 90], ...
'XTick',[0 60 120 180 240 300 360], ...
'Ytick',[-90 -60 -30 0 30 60 90]);
colormap(topomap1);
ylabel('Latitude [deg]');
xlabel('Longitude [deg]');
title('Voronoi Diagram, Capitals of Every Country');
scatter(lon,lat,'.r');
print(fig,'filename','-djpeg','-r600');```

% Capitals of Every Country