function COORDS = evenPtsSqr2d(n);
% Evenptsf(n) - This function will place evenly- spaced points on a plane.
% The number of points to generate (n) must be a perfect square, due to the way 
% the points are generated.



% The variables:
s = sqrt(n);                 
A =  3.125 * pi * n;        % the total area needed; a circle of 9*pi square body 
L = sqrt(A);                % lengths per fish; L is the length of a side of the 
spac = L / s;               % plane.  Spac is the spacing constant for placing the
                            % points, i.e. places them at a constant distance.
plac = (.5 * (s - 1));      % Determines the placement of the points, so that 
                            %  they center around (0,0), for ease of making 
                            %  groups.
                            
% Check to see if n is a perfect square.                      
if s ~= round(s) 
    error('n must be a perfect square')
end


% Sets default n to 100.
if exist('n') == 0
    n = 100;
end


% First, the COORDS matrix is initialized, to be filled later.
COORDS = [];

% Next, points are generated
for row = -plac:plac                  % Loop over each y-coord, called a "row".
    rowy = row * spac ;               % Place the points, set in intervals by 
                                      % by the spac constant, and placed in the
                                      % middle of each interval by spac/2.
    
    for col = -plac:plac              % Loop over all x-values for each y.
        colx = col * spac ;           % Place x's, as above.
        coords = [colx rowy];         % Now, each points is set as a 'coord'.
        
        COORDS = [COORDS; coords];    % COORDS matrix is built of each point, 
                                      % row by row.
    end
end
COORDS;

%  NCOORDS = [[1:n]' COORDS];           % Gives a number for each point, and
                                      % new matrix is called NCOORDS (numbered
                                      % coordinates).
                                        
 %plot(NCOORDS(:,2),NCOORDS(:,3),'.')       % plot the points for a visual check.
    
