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

Click For Summary

Discussion Overview

The discussion revolves around creating a circle within a square divided into 8x8 parts using MATLAB. Participants explore the problem of plotting a circle in a checkerboard pattern and share code snippets and ideas related to the task.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant seeks assistance in creating a circle within a square divided into 8x8 sections in MATLAB.
  • Another participant suggests that the original poster should provide more details about their understanding and any code they have attempted.
  • A participant shares a code snippet that includes the generation of a circle and random particle movement within that circle.
  • There is a mention of using the formula x² + y² = r² for plotting the circle on the grid.
  • The original poster later indicates that they have figured out the solution to their problem.

Areas of Agreement / Disagreement

While there is a general agreement on the task of drawing a circle in a checkerboard pattern, the specifics of the implementation and the initial understanding of the problem vary among participants. The discussion remains somewhat unresolved as the original poster's final solution is not detailed.

Contextual Notes

Participants did not clarify the exact requirements or constraints of the problem, and there may be assumptions about the grid's dimensions and the circle's placement that are not explicitly stated.

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!
 

Similar threads

Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 1 ·
Replies
1
Views
12K
Replies
20
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K