% script to create rotated squares for rasteriazation trials
% http://www.geovista.psu.edu/sites/geocomp99/Gc99/076/gc_076.htm
%  HB 7 Sept 2006

% load with
% v.in.ascii in=rotating_sq.txt out=rotating_sq -n format=standard

side = 100;    % 100 units on a side

radius = sqrt( 2 * (side/2)^2 ); 

for deg = 5:5:45   % 5 deg changes from 5 to 45 deg

   theta = (deg+45) * pi/180;

   % calc corner coords
   coor_1 = radius * cos(theta);
   coor_2 = radius * sin(theta);

   % top rt
   x1= coor_1;
   y1= coor_2;

   % top left
   x2= -1 * coor_2;
   y2= coor_1;

   % bot left   
   x3= -1 * coor_1;
   y3= -1 * coor_2;

   % bot rt
   x4= coor_2;
   y4= -1 * coor_1;

   %centroids (offset a bit from each other)
   cen_x = 0.5*radius * cos(deg * pi/180);
   cen_y = 0.5*radius * sin(deg * pi/180);

   %output
   disp( sprintf('B 5') )
   disp( sprintf(' %.16f %.16f', x1, y1) )
   disp( sprintf(' %.16f %.16f', x2, y2) )
   disp( sprintf(' %.16f %.16f', x3, y3) )
   disp( sprintf(' %.16f %.16f', x4, y4) )
   disp( sprintf(' %.16f %.16f', x1, y1) )

   disp( sprintf('C 1 1') )
   disp( sprintf(' %f %f', cen_x, cen_y) )
   disp( sprintf(' 1 %d', deg) )
   disp( sprintf(' ') )  % v.in.ascii doesn't like blank lines
end
