How do I fill the centers and calculate the distance between two centerpoints in matalb?

4 ビュー (過去 30 日間)
Code for two randomly generated circles
figure;
x = rand(1,1);
y = rand(1,1);
r = rand(1,1);
th = 0:pi/100:2*pi;
a = r*cos(th)+x;
b = r*sin(th)+y;
plot(a,b);
hold on
x = rand(1,1);
y = rand(1,1);
r = rand(1,1);
th = 0:pi/100:2*pi;
a = r*cos(th)+x;
b = r*sin(th)+y;
plot(a,b);
hold off

採用された回答

Kevin Holly
Kevin Holly 2021 年 8 月 25 日
figure;
x = rand(1,1);
y = rand(1,1);
r = rand(1,1);
th = 0:pi/100:2*pi;
a = r*cos(th)+x;
b = r*sin(th)+y;
plot(a,b);
hold on
x2 = rand(1,1);
y2 = rand(1,1);
r = rand(1,1);
th = 0:pi/100:2*pi;
a = r*cos(th)+x2;
b = r*sin(th)+y2;
plot(a,b);
scatter(x,y,'filled')
scatter(x2,y2,'filled')
hold off
distance = sqrt((y2-y)^2+(x2-x)^2)
distance = 0.6040
  3 件のコメント
Kevin Holly
Kevin Holly 2021 年 8 月 25 日
編集済み: Kevin Holly 2021 年 8 月 25 日
It looks like you randomly generated the center points of the two circles. So, I labeled the coordinates of the second circle as x2 and y2. I used pythagorean theorem to find the distance between the centerpoints. Or did you want the distance from the outside of the circle? If that is the case, what if they overlap?
A Person
A Person 2021 年 8 月 25 日
Hi,
I only wanted the distance between the centerpoints, so this is perfect. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStrategy & Logic についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by