13 views (last 30 days)

Don Mathis
on 4 Jan 2019

Edited: Don Mathis
on 4 Jan 2019

Is this closer to what you want?

%% 100 points

rng(0)

xcord = rand(100,1)*100;

ycord = rand(100,1)*100;

xcordt = xcord';

ycordt = ycord';

radius = 5;

figure

new=[xcord ycord];

xxx=linspace(min(new(:,1)),max(new(:,1)),100);

yyy=linspace(min(new(:,2)),max(new(:,2)),100);

[XXX, YYY] = meshgrid(xxx,yyy);

D = pdist2([xcordt(:) ycordt(:)], [XXX(:) YYY(:)], 'euclidean', 'Smallest', 1);

sz = size(XXX);

reds = double(D<=radius) .* (1-D/radius);

blues = double(D>radius) .* ((D-radius)/max(D-radius));

Color = zeros([sz 3]);

Color(:,:,1) = reshape(reds, sz);

Color(:,:,3) = reshape(blues, sz);

image(xxx, yyy, Color);

set(gca, 'XLim', xxx([1 end]), 'YLim', yyy([1 end]), 'YDir', 'normal');

%% first 30 points

rng(0)

xcord = rand(100,1)*100;

ycord = rand(100,1)*100;

radius = 5;

figure

xcord = xcord(1:30);

ycord = ycord(1:30);

xcordt = xcord';

ycordt = ycord';

new=[xcord ycord];

xxx=linspace(min(new(:,1)),max(new(:,1)),100);

yyy=linspace(min(new(:,2)),max(new(:,2)),100);

[XXX, YYY] = meshgrid(xxx,yyy);

D = pdist2([xcordt(:) ycordt(:)], [XXX(:) YYY(:)], 'euclidean', 'Smallest', 1);

sz = size(XXX);

reds = double(D<=radius) .* (1-D/radius);

blues = double(D>radius) .* ((D-radius)/max(D-radius));

Color = zeros([sz 3]);

Color(:,:,1) = reshape(reds, sz);

Color(:,:,3) = reshape(blues, sz);

image(xxx, yyy, Color);

set(gca, 'XLim', xxx([1 end]), 'YLim', yyy([1 end]), 'YDir', 'normal');

Walter Roberson
on 18 Dec 2018

Walter Roberson
on 3 Jan 2019

N = 100; %100 square meters

subpixels = 4; %each square meter divided into 4 x 4

sensorradius = 5;

gridN = N * subpixels;

NC = 256; %number of entries in colormap

fullmap = true(gridN, gridN);

usemap = bwdistgeodesic(fullmap, round(x(:)*subpixels), round(y(:)*subpixels)); %note it takes C, R which is X, Y

image(uint8(usemap))

colormap(flipud(jet(NC)))

values in usemap start at 0 and go up. 0 is right at a sensor. Any value up to (sensorradius * subpixels) is considered covered and needs to be colored red. Maximum possible value is (sqrt(2) * N * subpixels) for the case where there is one sensor at one corner, with the maximum distance being at the diagonal opposite corner.

The part about subpixels has to do with the fact that if you were to use 1 pixel per meter then a radius of 5 would involve only an 11 x 11 section, which gives a very crude circle, not even remotely as smooth as what you show in your image. To make a smoother image, we divide each square meter into a 4 x 4 area to give a much smoother approximation. Coordinates in x and y would still be given in meters, but the distance map will be constructed 4 times larger to make the appearance much smoother.

Walter Roberson
on 9 Jan 2019

Use a higher subpixels value until you are satisfied with the smoothness.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.