%% iso_sizes.m    Hamish Bowman 2 July 2008
%%  released to the public domain
%%  calculate "A" paper sizes in mm and inches, from fundamentals


% ISO sizes:   A = [sizecode width_mm height_mm width_inches height_inches]
A(1:11,1) = [0:10];
A(1:11,2:5) = NaN;

area_A0 = 1.0; % sq-meter
M_TO_INCH = 0.0254;

%%%
%length * width = area_A0;
%width = area_A0/height
%
%height = width * sqrt(2)
%height = (area_A0/height) * sqrt(2)
%height^2 = area_A0 * sqrt(2)
%%
% thus:
% height_A0 = sqrt( area_A0 * sqrt(2) ); % in meters
% width_A0 = area_A0/height; % in meters
% A(1,2) = width_A0 / M_TO_INCH;
% A(1,3) = height_A0 / M_TO_INCH;

for size=0:10
   area_sheet = area_A0 / (2^size);
   height = sqrt( area_sheet * sqrt(2) ); % in meters
   width = area_sheet/height; % in meters
   A(size+1,2) = width * 1000; % mm
   A(size+1,3) = height * 1000; %mm
   A(size+1,4) = width / M_TO_INCH; % inches
   A(size+1,5) = height / M_TO_INCH; % inches
end


disp( sprintf('size|width_mm|height_mm|width_inch|height_inch') )
for size = 0:10
  disp( sprintf('A%d|%.2f|%.2f|%.3f|%.3f', A(size+1,1:5)) )
end

%% result:
%  size|width_mm|height_mm|width_inch|height_inch
%  A0|840.90|1189.21|33.106|46.819
%  A1|594.60|840.90|23.410|33.106
%  A2|420.45|594.60|16.553|23.410
%  A3|297.30|420.45|11.705|16.553
%  A4|210.22|297.30|8.277|11.705
%  A5|148.65|210.22|5.852|8.277
%  A6|105.11|148.65|4.138|5.852
%  A7|74.33|105.11|2.926|4.138
%  A8|52.56|74.33|2.069|2.926
%  A9|37.16|52.56|1.463|2.069
%  A10|26.28|37.16|1.035|1.463

