I need help with a Fill a figure with 1 and 0
조회 수: 2 (최근 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!

