Combination of distances between multiple points

3 次查看(过去 30 天)
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!

采纳的回答

Rik
Rik 2021-7-29
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
combs = 15×3
1.0000 2.0000 7.9112 1.0000 3.0000 8.4890 1.0000 4.0000 8.4228 1.0000 5.0000 5.9644 1.0000 6.0000 21.6430 2.0000 3.0000 28.6815 2.0000 4.0000 34.0819 2.0000 5.0000 1.8794 2.0000 6.0000 11.5847 3.0000 4.0000 3.2875
%(circle 1, circle 2, distance)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Automotive 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by