Pseudo-random distribution of points with minimum distance

27 views (last 30 days)
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
James Tursa on 28 Mar 2019
I wasn't suggesting eliminating the offenders, but pushing them away from each other until they are not offending anymore.

Sign in to comment.

Accepted Answer

Torsten on 29 Mar 2019
See Bruno Luong's code under

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 29 Mar 2019
See my attached demo that I've posted before.
Bruno Luong
Bruno Luong on 20 May 2021
Edited: 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.

Sign in to comment.

Image Analyst
Image Analyst on 19 May 2021
@Jeroen Houwen, see attached demo of Fry Plot.

Community Treasure Hunt

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

Start Hunting!

Translated by