# Homework Help: Make a circle in square that is split 8x8 parts?

Tags:
1. Feb 22, 2016

### Lucas94

• Member warned about posting with no effort and without the template
Sorry if i may sound little unclear, english is not my first langue. I im looking for a way to create a circle that is in a square cut in 8x8 in matlab. I would be glad if someone could give me a hand.
Thanks!

2. Feb 22, 2016

### Staff: Mentor

Welcome to PF!

This looks like homework so you need to show us what you know and some code of what you've tried.

Also a better description of the problem you are trying to solve.

My initial thought was you are trying to draw a circle in a checkerboard (8x8 squares) but I think it may be more than that.

3. Feb 22, 2016

### Lucas94

Code (Matlab M):

Np   = 400;         % Number of Particles
t    = 10^3;        % Time
M    = zeros(Np,2); % Predefined
Msaf = zeros(Np,2); % Predefined
modi = 0.1;         % Movement modification
rng('shuffle')      % More random

% Circle
cv = linspace(0,2*pi,100);
cx = r*cos(cv);
cy = r*sin(cv);
%axis square
% Circle

for Pic=1:t

Direction=randi([-1,1],Np,2);
Movement=Direction*modi;

Msaf=M+Movement;

if sqrt(Msaf(:,1).^2+Msaf(:,2).^2)<r
M=M+Movement;

else
Msaf=M;
t=t-1;

end

plot(cx,cy,'b','Linewidth',2.5)
%axis equal
axis([-r r -r r]);
grid on
axis square

hold on

scatter(M(:,1),M(:,2),'r','filled');

pause(0.001)
%drawnow
hold off

if t==(100/t)*50
disp('50%')
end
if t==(100/t)*70
disp('70%')
end
if t==(100/t)*90
disp('90%')
end
if t==(100/t)*100
disp('100%')
end
end

Last edited by a moderator: Feb 22, 2016
4. Feb 22, 2016

### Lucas94

Yes i'm trying to draw a circle in a checkerboard (8x8 squares)

5. Feb 22, 2016

### Staff: Mentor

And you need a formula like x^2 + y^2 = r^2 to plot in the 8x8 grid?

6. Feb 23, 2016

### Lucas94

ive figured it out now! Thanks for your help!