Combination of distances between multiple points
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mirza Ahmed
am 29 Jul. 2021
Kommentiert: Mirza Ahmed
am 3 Aug. 2021
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 Kommentare
Akzeptierte Antwort
Rik
am 29 Jul. 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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!