Combination of distances between multiple points
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a number of circles, where I can define the number at the beginning, i = number of circle. I have to calculate every minimum distance between every circle. That means the equation can be written as:
dist = (x1-x2)^2 + (y1-y2)^2 - (r1+r2)
Let's say the number of circle is chosen 6, so the number of combination of distances come as 15.
To define the variables first, I have declared the matrices of radius, x coordiantes and y coordinates. Now, from this point onwards, I need help to write the basic and generalized code to find the combination.
Thanks!
0 commentaires
Réponse acceptée
Rik
le 29 Juil 2021
You already have the generalized code. You just need to combine it with nchoosek:
x=1+10*rand(1,6);
y=1+10*rand(1,6);
r=rand(1,6);
combs=nchoosek(1:6,2);
c1=combs(:,1);c2=combs(:,2);
d=(x(c1)-x(c2)).^2 + (y(c1)-y(c2)).^2 - (r(c1)+r(c2));
combs(:,3)=d
%(circle 1, circle 2, distance)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Performance and Memory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!