# How to create a circle filled with equidistant points inside it?

7 次查看（过去 30 天）
Rushil Asthana2021-10-6

I want to create circle filled with equidistant points inside it. I have tried making the following program but it's taking too long to give output
xc = 1;
yc = xc+1;
jc= 1;
jy=jc+1;
for i=xc:yc:area
theta = i*(2*pi);
for j=jc:jy:i
x = xc + r.*cos(theta);
y = yc + r.*sin(theta);
end
plot(x,y,'.')
end
##### 5 个评论显示隐藏 4更早的评论
Rushil Asthana 2021-10-6
@John D'Errico What will the code look like essentially? Cause I need help with exactly what you mentioned.

### 采纳的回答

Chunru 2021-10-7

Here is a sub-optimal (or almost optimal) solution. Filled dots will form the hexagonal formation.
d = 1; % distance
xall=[]; yall=[];
dy = sqrt(3)/2 * d;
for i=-ny:ny
y = dy*i;
if rem(i, 2)==0
x = (-nx:nx)'*d;
else
x = (-nx-0.5:nx+0.5)'*d;
end
xall = [xall; x];
yall = [yall; y*ones(size(x))];
end
plot(xall(:), yall(:), '.');
hold on
theta = 0:360;
axis equal
##### 3 个评论显示隐藏 2更早的评论
Chunru 2021-10-7
@Image Analyst Thanks for cultivating the good community culture. :-)

### Community Treasure Hunt

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

Start Hunting!

Translated by