如何创建具有重叠圆的图,其中重叠区域根据与其重叠的圆的数量进行颜色编码?
clear;
noOfNodes = 200;
x = rand(1,1000 )*1000;
y = rand(1,1000 )*1000;
R = 8;
netXloc = x;
netYloc = y;
grid on
set(gca, 'GridLineStyle', '-');
grid(gca,'minor')
hold on
scatter ( x, y, 'R.');
axis square
hold on
axis ( [ 0.0, 1000.0, 0.0, 1000.0 ] )
title ( 'WSN coverage' );
hold off
for i = 1:1000
ctr = [x(i) y(i)]-R;
diameter = 2*R;
h = rectangle('Position',[ctr,diameter,diameter],'FaceColor',[0.5 0.5 0.5],'Curvature',[1,1],'LineWidth',.5,'LineStyle','-');
alpha .6;
end;
答案 0 :(得分:1)
以下是如何操作:
% size of image
sz = [800 800];
% generate coordinates
y = 1:sz(1);
x = 1:sz(2);
[xx yy] = meshgrid(x,y);
% draw circles
ci1 = (xx-300).^2 + (yy-400).^2 <= 200^2;
ci2 = (xx-500).^2 + (yy-400).^2 <= 200^2;
ci3 = (xx-400).^2 + (yy-300).^2 <= 200^2;
ci4 = (xx-400).^2 + (yy-500).^2 <= 200^2;
% draw image containing circles
figure; imagesc(ci1 + ci2 + ci3 + ci4);
结果如下: