I need help with a Fill a figure with 1 and 0
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Carlos Santiago Rodríguez Sarmiento
am 10 Mär. 2022
Beantwortet: Walter Roberson
am 10 Mär. 2022
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 Kommentare
Antworten (1)
Walter Roberson
am 10 Mär. 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
smallest_x
imshow(hypo)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dictionaries finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

