% BEM-LAP-MAT project
% Matlab/Freemat codes
% Copyright 2008 Stephen Kirkup 
% http://www.researchgate.net/profile/Stephen_Kirkup
% University of Central Lancashire
% Issued under the GNU General Public License 2007, see gpl.txt
% www.boundary-element-method.com
% contact: stephen@boundary-element-method.com
% http://www.researchgate.net/profile/Stephen_Kirkup


% function [vertpts,elemvert]=square 
% Returns a list of edges of the panels that make up the square
%  in vertpts and the list of elements that make up the boundary
%  are defined by the indices of the two vertices in elemvert.
% Note that the vertices of each element in elemvert must be
%  defined in the clockwise direction.

function [vertpts,elemvert]=square_general(n,dimension, centre, clockwise)
    
    if (round(n/4)*4~=n) 
        'Error the number of elements must be a multiple of 4'
    else
    
    panelsize=4.0/n;
    nside=n/4;
      for (k=1:nside)
        vertpts(k,1)=-0.5;
        vertpts(k,2)=-0.5+(k-1)*panelsize; 
        vertpts(k+nside,1)=-0.5+(k-1)*panelsize;
        vertpts(k+nside,2)=0.5;
        vertpts(k+2*nside,1)=0.5;
        vertpts(k+2*nside,2)=0.5-(k-1)*panelsize;
        vertpts(k+3*nside,1)=0.5-(k-1)*panelsize;
        vertpts(k+3*nside,2)=-0.5;
      end 
      vertpts=vertpts*dimension;
      for k=1:n
          vertpts(k,:)=vertpts(k,:)+centre(:)';
      end 
% MAY NEED TO TRANSPOSE ELEMVERT   
      if (clockwise)       
        elemvert=[1:n; 2:n+1];
        elemvert(2,n)=1;
      else
       elemvert=[n:-1:1;n-1:-1:0];
        elemvert(1,2)=n; 
      end    
   end         
 end
           
           
  
  
           
