Make a circle in square that is split 8x8 parts?

AI Thread Summary
The discussion focuses on creating a circle within an 8x8 square grid using MATLAB. The original poster seeks assistance and clarification on the problem, which is confirmed to involve drawing a circle in a checkerboard pattern. Participants suggest providing code examples and a clearer problem description to facilitate help. The poster successfully resolves the issue by utilizing the formula x^2 + y^2 = r^2 for plotting the circle. The thread concludes with the poster expressing gratitude for the assistance received.
Lucas94
Messages
7
Reaction score
0
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 I am 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!
 
Physics news on Phys.org
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.
 
Matlab:
Np   = 400;         % Number of Particles
t    = 10^3;        % Time
M    = zeros(Np,2); % Predefined
Msaf = zeros(Np,2); % Predefined
modi = 0.1;         % Movement modification
r    = 8;           % Radius
rng('shuffle')      % More random

% Circle
cv = linspace(0,2*pi,100);
cx = r*cos(cv);
cy = r*sin(cv);
%axis square
% Circlefor 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

<<Moderator's note: CODE tags added.>>
 
Last edited by a moderator:
Yes I'm trying to draw a circle in a checkerboard (8x8 squares)
 
And you need a formula like x^2 + y^2 = r^2 to plot in the 8x8 grid?
 
ive figured it out now! Thanks for your help!
 
Back
Top