我正在尝试在网格网格中生成同心圆,但我使用的代码只绘制了圆圈的边框。
theta = linspace(0, 2*pi, 100);
[X, Y] = meshgrid(1:1:4, theta);
a = 0;
b = 0;
plot(a+cos(Y).*X, b+sin(Y).*X);
axis equal
我打算做的是生成填充的同心圆,圆圈内的点的值为1(白色)或0(黑色)。下面是可视化图片。你如何使用MATLAB编写代码?
谢谢,
答案 0 :(得分:1)
你需要稍微使用meshgrid:
var obj = {};
var arr = Object.keys(obj);
console.log(arr);
console.log("Is Empty : " + (arr.length == 0));
现在尝试:
N=200; % some size of grid
if mod(N,2) % odd vs even matrix sizes
[x,y] = meshgrid(-(N-1)/2:(N-1)/2);
else
[x,y] = meshgrid(-N/2+1:N/2);
end
x0=0; y0=0; % assuming the circle are always in the center, but we can modify this if needed
% say we want a ring between `r1` and `r2`
f = @(r1,r2) (x-x0).^2+(y-y0).^2<=r2^2 & ...
(x-x0).^2+(y-y0).^2>=r1^2;
imagesc(f(30,40)+f(50,60))
是一个逻辑矩阵,对于由两个半径为f
和r1
的圆之间的区域给出的条件,其值为1 ....您只关心半径,因为始终满足r2
坐标(或0到2pi之间),因此它不相关......