Generate random points on rectangular area.
5 views (last 30 days)
Show older comments
Phillip Oni
on 15 Jul 2014
Commented: Phillip Oni
on 15 Jul 2014
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
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.
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!