38 views (last 30 days)

Show older comments

Hi all,

I use the following code to generate an exact number of points (650 in this case) within a one hectar area:

numPoints = 650; % number of points to be generated

width = 100; % length in m of one square side

x = 0;

y = 0;

figure('Position', [300 300 900 900])

rectangle('Position', [x, y, width, width],'LineWidth',2,'LineStyle','--');

grid on;

hold on;

xRandom = 50 + (width * rand(1, numPoints) - width / 2);

yRandom = 50 + (width * rand(1, numPoints) - width / 2);

plot(xRandom, yRandom, 'b.', 'MarkerSize', 8);

hold on;

plot(xRandom, yRandom, 'ro', 'MarkerSize', 20);

title(['',num2str(numPoints),' points inside one hectar'], 'Interpreter', 'None');

xlabel('length in meters');

ylabel('length in meters');

axis equal tight;

What I would like to achieve is that the minimum distance between these points is 3 meters. This condition is fulfilled if the red circles (with 3 m diameter - only approximated here using MarkerSize) only touch each other but don't overlap as they currently do (see image below).

Does anybody know how to accomplish this?

PS: at a completely regular spacing of 650 points in one hectar there would be 4 m distance between each point. Maybe a possible solution would be to create a regular spacing first and then add or substract a smaller random increment?

James Tursa
on 28 Mar 2019

Torsten
on 29 Mar 2019

See Bruno Luong's code under

https://de.mathworks.com/matlabcentral/answers/432516-model-of-a-crowd-on-concert-venue-or-how-to-distribute-random-points-according-to-the-2d-window-dist

Image Analyst
on 29 Mar 2019

See my attached demo that I've posted before.

Bruno Luong
on 20 May 2021

"With a Gaussian distribution, and a finite number of samples drawn from it, it's certainly possible to not encounter any negative values."

Fine but that has nothing to do my comment, which is one can NEVER generate a Gaussian random distribution with a positive values. I'm not talking about the reverse.

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!