How to tell whether or not 5 or more lines intersect
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
To the left is 4 intersections, and I am trying to control the number of line intersections in my loop. The intersections I am particularly interested are coming from the chords created from intersecting circles. I want to discard iterations that create of 5 or more line intersections. How do I do that?
n = 50; % Number of circles
m = 1000; % Number of points on circle
r_max = 85; % Maximum circle radius
r_min = 30; % Minimum circle radius
x_max = 720; % Uppermost x location of circle center
y_max = 360; % Uppermost y location of circle center
theta = 0:2*pi/m:2*pi; % Evaluated angles for circle
rad = r_max*rand(1,n); % Set radius array size
x_pos = x_max*rand(1,n); % Set x-position array size
y_pos = y_max*rand(1,n); % Set y-position array size
i = 1; % Looping value
j = 1; % Circle data pointer
while i<=n
j = i+1;
while j<=n % Partnering first circle with other circles
[xout,yout] = circcirc(x_pos(i),y_pos(i),rad(i),x_pos(j),y_pos(j),rad(j));
mapshow(xout,yout,'DisplayType','point','Marker','o')
plot(line([xout(1) xout(2)],[yout(1) yout(2)]))
axis([0 x_max 0 y_max]);
hold on
j = j+1;
end
i = i+1;
end
0 commentaires
Réponse acceptée
Jian Wei
le 21 Juil 2014
After you generate the circle centers and their radii, you can run the following code to find the indices of the iterations that create less than 5 intersections.
% find each pair of circles which intersect with each other and store the information in matrix M
M = zeros(n);
for i=1:n-1
for j=i+1:n
if norm([x_pos(i)-x_pos(j),y_pos(i)-y_pos(j)])<rad(i)+rad(j) && norm([x_pos(i)-x_pos(j),y_pos(i)-y_pos(j)])>abs(rad(i)-rad(j))
M(i,j)=1;
M(j,i)=1;
end
end
end
% identify the iteration index which creates less than 5 intersections
index = zeros(n,1);
for i = 1:n
ind = find(M(:,i)~=0);
if ~isempty(ind)
if length(ind)>=5
continue;
else
M1 = M(ind,ind);
if length(ind)+1/2*sum(sum(M1))>=5
continue;
else
index(i)=1;
end
end
end
end
idx = find(index~=0);
The indices of the iterations which create less than 5 intersections are stored in the variable idx. Iterate on idx, and you can discard iterations that create 5 or more than 5 intersections.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Delaunay Triangulation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!