% trnglDefB.m
%          10 September 2004
%                  from trnglDef.m from  TrikoorinEnglish.m  
% conversion to decimal representation of trianglel
% 
% Here the compositions by Tex (Swedish painter) are coded. 
% Each composition consists of three equilateral colored triangles. 
% The length of edges is fixed and specified for plotting
%
% Each triangle is determined by the x- and  y-coordinates for the 
% leftmost corner and by the 90o - rotation angle with respect of this corner
%   or angle between a vertical and the side down to lowest corner. 
% Each coordinate is given by eight bits. 
%         For x and y the resolution will be 0.5 mm.
% Angles are determined by seven bits. 
%        The resolution will thus be one  degree.
% Each triangle is colored red, green or blue. The intensity for each color
% is given by two bits. A red triangle thus has the color vector 
% [3 0 0] =  [1 1 0 0 0 0], a green triangle has the color vector 
% [0 3 0] =  [0 0 1 1 0 0], a blue triangle has the color vector
% [0 0 3] =  [0 0 0 0 1 1].
% Hence, each composition is coded by 3(8+8+7+6) = 87 bits.
% Each set consists of four compositions (triples od triangles)
% There are four sets called  TA, TB, TC, TD

clear
%    lengths of triangle sides  in mm
edg = [12 25 41];
vv = [0 ; 1 ; exp(j*pi/3)] ; % vertices of a unity equilateral triangle 
vrt = vv*edg ;

m = 87 ;  % number of bits in triangle specification (number of neurons)

 %  TB set contains a variety of triangles
 %       x    y    deg   r  g  b
 TBd = [14   57.5   37   3  0  0
        36   55    101   0  0  3
        17.5 16.5   43   0  3  0 
 %  
        51   32     45   0  0  3
        25.5 14    101   0  3  0
        21   19     38   3  0  0 
 %
        53  44.5   106   0  3  0
        20  10      41   3  0  0
        6   37.5    67   0  0  3
 %
        8.5 14.5   70    3  0  0
       45   46.5   80    0  3  0
       29.5 28     19    0  0  3
 %
       16    84     0    3  0  0
       21    22    60    0  0  3 
       21    59.5  58    0  3  0 ]; %  15 x 6
   
 %  scans TBd row-wise and converts each number to an 8-bit string 
 % check first the following sequence of functions to see the structure
 %  Bt = dec2bin(TBd',8) , bin2dec(Bt)
 
 Bt = (dec2bin(2*TBd',8) - '0')'; %  is is  8 x 5*3*6
 B = reshape(Bt, 8*3*6, 5) ;    %  is 8*3*6 x 5
 % We need the following bits (rows of B)
 k = [1:8 (1:8)+8 (1:7)+2*8 (6:7)+3*8 (6:7)+4*8 (6:7)+5*8] ;
 k = [k k+48 k+2*48] ;
 TB = B(k,:) ;   % is 87 x 5
 
 % recoding each set from {0, 1}  to {-1, +1}
 TB = 2*TB - 1;


