Plot only equilateral triangles

1 回表示 (過去 30 日間)
Mayur Deogade
Mayur Deogade 2020 年 9 月 4 日
回答済み: Alan Stevens 2020 年 9 月 5 日
Plot random 10 triangles and plot only almost equilateral triangles. Check whether the three edges differ by less than a chosen small constant, for example e = 0.01. I have drawn the random triangles but I need to plot only equilateral triangles. So far, I get any random triangles including obtuse, acute and equilateral triangles.
  3 件のコメント
Mayur Deogade
Mayur Deogade 2020 年 9 月 4 日
編集済み: Mayur Deogade 2020 年 9 月 4 日

figure, hold on

for i=1:10 Fill(rand(3,1), rand(3,1), rand(1,3))

End

Axis([0 1 0 1])

Axis square off

Mayur Deogade
Mayur Deogade 2020 年 9 月 4 日
Here, I am able to plot 10 random triangles but I need to plot only triangles which are nearly equilateral

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

採用された回答

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 9 月 5 日
figure, hold on
e = 0.01;
i=0;
while i<= 10
x = rand(3,1);
y = rand(3,1);
c = rand(3,1);
L1 = sqrt((x(2)-x(1)).^2 + (y(2) - y(1)).^2);
L2 = sqrt((x(3)-x(1)).^2 + (y(3) - y(1)).^2);
L3 = sqrt((x(3)-x(2)).^2 + (y(3) - y(2)).^2);
L = sort([L1, L2, L3]);
if L(2)-L(1) < e && L(3) - L(2) <e && L(3)-L(1) < e
i = i + 1;
fill(x,y,c)
end
end
axis([0 1 0 1])
axis square off

その他の回答 (2 件)

Alan Stevens
Alan Stevens 2020 年 9 月 5 日
Here's an alternative approach:
e = 0.01;
for i = 1:10
xc = rand(1); yc = rand(1);
r = rand(1);
while r < e/sqrt(3)
r = rand(1);
end
theta1 = 2*pi*rand(1);
theta = [theta1;
theta1 + 2*pi/3;
theta1 + 4*pi/3];
x = xc + r*cos(theta);
y = yc + r*sin(theta);
plot([x; x(1)],[y; y(1)])
hold on
end
axis equal off

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 9 月 5 日
figure, hold on
e = 0.0001;
i=0;
while i<= 10
x = rand(3,1);
y = rand(3,1);
c =rand(3,1);
L1 = sqrt((x(2)-x(1)).^2 + (y(2) - y(1)).^2);
L2 = sqrt((x(3)-x(1)).^2 + (y(3) - y(1)).^2);
L3 = sqrt((x(3)-x(2)).^2 + (y(3) - y(2)).^2);
L = sort([L1, L2, L3]);
if L(2)-L(1) < e || L(3) - L(2) <e
i = i + 1;
fill(rand(3,1), rand(3,1), rand(1,3))
end
end
axis([0 1 0 1])
axis square off
  1 件のコメント
Mayur Deogade
Mayur Deogade 2020 年 9 月 5 日
It's plotting all the triangles
Acute obtuse

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by