I need help with a Fill a figure with 1 and 0
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
smallest_x
imshow(hypo)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dictionaries 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!