1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

Tags:
  1. Feb 22, 2016 #1
    • 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. jcsd
  3. Feb 22, 2016 #2

    jedishrfu

    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.
     
  4. Feb 22, 2016 #3
    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
    r    = 8;           % Radius
    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
     
    <<Moderator's note: CODE tags added.>>
     
    Last edited by a moderator: Feb 22, 2016
  5. Feb 22, 2016 #4
    Yes i'm trying to draw a circle in a checkerboard (8x8 squares)
     
  6. Feb 22, 2016 #5

    jedishrfu

    Staff: Mentor

    And you need a formula like x^2 + y^2 = r^2 to plot in the 8x8 grid?
     
  7. Feb 23, 2016 #6
    ive figured it out now! Thanks for your help!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Make a circle in square that is split 8x8 parts?
  1. Numerical Array split (Replies: 9)

Loading...