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

1 vue (au cours des 30 derniers jours)
Carlos Santiago Rodríguez Sarmiento
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

Réponses (1)

Walter Roberson
Walter Roberson le 10 Mar 2022
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)

Catégories

En savoir plus sur Dictionaries dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by