for the same answer,,suppose, X ranges from 1 to 500, y ranges from 1 to 200 , Is it possible to find how many such coordinates are possible so that distance from each and every coordinate to other coordinate is > 20

2 visualizzazioni (ultimi 30 giorni)
BWremain = true(300);
% Number of random coordinates
N = 100;
% Selected coordinates are stored these variables
row = nan(N,1);
col = nan(N,1);
for kk = 1:N
BW = false(300);
p = find(BWremain);
p = p(randperm(numel(p),1));
BW(p) = true;
BW = bwdist(BW) > 20;
BWremain = BWremain & BW;
[row(kk),col(kk)] = ind2sub(size(BWremain),p)
end
  2 Commenti
M.Prasanna kumar
M.Prasanna kumar il 14 Dic 2018
suppose x & y ranges from 1 to 300 , let number of random coordinates N = 5000 or more, is it possible to get 5000 or more (x,y) coordinate points which are equidistant to each other (here it is 20). my doubt is there is limit of 300 for x and y values. In the limited domain (area) . I'm thankful to your answer. but for the same code N = 500.
Error using randperm
K must be less than or equal to N.
Error in randmnum (line 27)
p = p(randperm(numel(p),1));)
above error is getting.
so doubt have raised in my mind

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 14 Dic 2018
Modificato: Image Analyst il 14 Dic 2018
The max number varies depending on what points were actually placed. Using numbers from your question, and trying a million coordinates, we can see that we can place from about 150 to 200 points. See code below:
pointsToPlace = 5000000 ; % # of random coordinates we need to place - some huge number
% Preallocate points
x = zeros(1, pointsToPlace);
y = zeros(1, pointsToPlace);
loopCounter = 1;
maxIterations = 1000000; % Number of tries before giving up.
numberPlaced = 0; % No points placed yet.
while numberPlaced < pointsToPlace && loopCounter <= maxIterations
% Get new coordinate
xProposed = 1 + (500-1)*rand(); %% random X- coordinates
yProposed = 1 + (200-1)*rand(); %% random Y- coordinates
if loopCounter == 1
% First one automatically gets added of course.
numberPlaced = 1;
x(numberPlaced) = xProposed;
y(numberPlaced) = yProposed;
else
% Compute distance to all prior coordinates.
distances = sqrt((xProposed - x(1:numberPlaced)) .^ 2 + (yProposed - y(1:numberPlaced)) .^2);
% If less than 20, add it
if min(distances > 20)
numberPlaced = numberPlaced + 1;
x(numberPlaced) = xProposed;
y(numberPlaced) = yProposed;
end
end
loopCounter = loopCounter + 1;
end
% Crop to how many we actually got.
x = x(1:numberPlaced);
y = y(1:numberPlaced);
fprintf('Placed %d points after %d iterations\n', numberPlaced, loopCounter-1);
plot(x, y, 'b*', 'LineWidth', 2, 'MarkerSize', 14);
grid on;
axis equal
xlim([0, 500]);
ylim([0, 200]);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
0001 Screenshot.png
I'm not aware of an analytical statistical answer, so above we solve it numerically.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by