-2

如何创建一个带有重叠圆圈的图,其中重叠区域根据重叠的圆圈数量进行颜色编码?

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; 
4

1 回答 1

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);

结果如下:

在此处输入图像描述

于 2013-02-07T21:14:11.083 回答