I'm trying to randomly create 100 points from 0 - 180, then graph them. Then check the distance between them and if it falls under a certain threshold draw a line between them. I can get the points graphed, and even some lines. But it's not right, some points that are close enough aren't mapped, and some points that are further are mapped.
clc; clear all; format compact;
a = [2 3]
b = [16 50]
array = randi(180,100,1);
array2 = randi(180,100,1);
% x = array(:, 1);
% y = array(:,2);
plot(array,array2, '.')
line (a,b)
% radius is 18, which is given k * given d
for j = 1:100
for i = 1:100
d = sqrt((array(j)-array(i))^2+(array2(j)-array2(i))^2);
if d <= 18
point1 = [array(j), array2(j)];
point2 = [array(i), array2(i)];
line( point1, point2)
end
end
end
Sample output:
Aucun commentaire:
Enregistrer un commentaire