Generate random points on rectangular area.

5 views (last 30 days)
I am working on generating multiple access point on a 190 X 90 (meters) area, each access point is 20 m apart. I want to use point to represent an access point, but each point must be separated by 20m on the surface area. I will appreciate any help.
  1 Comment
John D'Errico
John D'Errico on 15 Jul 2014
I'd suggest you do it iteratively. Choose one point at random. Then find a new random point that is not within the designated distance from any previous points.
To do that efficiently, you will probably want to learn about Voronoi diagrams & polygons.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 15 Jul 2014
You may not be able to do it. Try this code to get you started:
clc;
clear all;
count = 1;
numberOfTries = 1; % Failsafe variable.
while count < 190 && numberOfTries < 1000
x(count) = 190 * rand(1);
y(count) = 190 * rand(1);
numberOfTries = numberOfTries + 1
if count > 1
distances = sqrt((x(1:end-1)-x(count)).^2 + (y(1:end-1)-y(count)).^2);
minDistance = min(distances);
if minDistance > 20
% Increment if we've found one far enough away.
count = count + 1
end
elseif count == 1
% Increment from 1 to 2
count = count + 1;
end
plot(x, y, 'b*');
drawnow;
end
  1 Comment
Phillip Oni
Phillip Oni on 15 Jul 2014
Quite close. I can play around with it to fit my need. Thank you very much for the swift response.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!