I need help with a Fill a figure with 1 and 0

2 ビュー (過去 30 日間)
Carlos Santiago Rodríguez Sarmiento
Carlos Santiago Rodríguez Sarmiento 2022 年 3 月 10 日
回答済み: Walter Roberson 2022 年 3 月 10 日
r1 = 30;
k = 3;
r2 = r1/k;
hypo = zeros(200,200);
for t = 0:0.001:2*pi
x=round((r1-r2)*cos(t)+r2*cos((1-k)*t));
y=round((r1-r2)*sin(t)+r2*sin((1-k)*t));
if x ~= 100
m = y/x;
if x>0
for i = 0:0.001:x-0.1
y2 = round(m*i);
hypo(round(100+y2),round(100+x))=1;
end
else
for l = x+0.1:0.001:0
y3 = round(m*l);
hypo(round(100+y3),round(100+x))=1;
end
end
else
for r = -y:1:y
hypo(100+r,100)=1;
end
end
end
imshow(hypo)
I have this code but the second part of the if x~=100 doesn't run, I need fill a rect because I need the fourier transformation of the figure

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 3 月 10 日
Your x values start at r1 = 30 and go down from there, as far as -15. In each case, x ~= 100 is true, so there is never a reason to run the else
r1 = 30;
k = 3;
r2 = r1/k;
hypo = zeros(200,200);
biggest_x = -inf;
smallest_x = inf;
for t = 0:0.001:2*pi
x=round((r1-r2)*cos(t)+r2*cos((1-k)*t));
biggest_x = max(x, biggest_x);
smallest_x = min(x, smallest_x);
y=round((r1-r2)*sin(t)+r2*sin((1-k)*t));
if x ~= 100
m = y/x;
if x>0
for i = 0:0.001:x-0.1
y2 = round(m*i);
hypo(round(100+y2),round(100+x))=1;
end
else
for l = x+0.1:0.001:0
y3 = round(m*l);
hypo(round(100+y3),round(100+x))=1;
end
end
else
for r = -y:1:y
hypo(100+r,100)=1;
end
end
end
biggest_x
biggest_x = 30
smallest_x
smallest_x = -15
imshow(hypo)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by