function A = CinDir20dof( DM )

q       = DM.q(DM.fase,:);
L       = DM.L;
XYZRef  = DM.XYZRef(DM.fase,:);
pe      = DM.pe(DM.fase,:);


%-- Parametros de Denavit-Hartenberg -------------------------------------------------
 if(strcmp(pe,'dir'))
     DH = [ q(1)       0          L(2)    pi/2    %-- Perna direita: S1 -> S6=S6'
            q(2)       0          L(3)    0
            q(3)       0          L(4)    0
            q(4)       0          L(5)   -pi/2
            q(5)       0          L(6)    0
           -pi/2       0          0      -pi/2                      

            q(6)-pi    0         -L(8)    0       %-- Anca: S6' -> S7

            q(7)      -L(6)       0      -pi/2    %-- Perna esquerda: S7 -> S13
            q(8)+pi/2  0          L(5)    pi/2
            q(9)       0          L(4)    0
            q(10)      0          L(3)    0
            q(11)      0          L(2)   -pi/2
            q(12)      0          L(1)    0      

            q(6)-pi    L(7)      -L(8)/2 -pi/2      %-- Tronco inferi:  S6' -> S14 
           -pi/2       0          L(9)    0         %--                 S14 -> S15
            q(13)      0          L(10)   pi/2      %--                 S15 -> S16
            q(14)      0          L(11)        0    %--                 S16 -> S17

            0          0          L(12)+L(13)  0    %-- Tronco/Cabeça:  S17 -> S18
            pi/2       0          0            pi/2 %--                 S18 -> S18' 
            q(15)      L(14)      0           -pi/2 %--                 S18'-> S19
            q(16)-pi/2 0          L(15)        0    %--                 S19 -> S20

            q(14)     -L(8)/2-L(16) L(11)+L(12)  pi   %-- Braço direito:
            q(17)      L(17)        0            pi/2
            q(18)-pi   0            L(18)        0

            q(14)      L(8)/2+L(16) L(11)+L(12)  0    %-- Braço esquerdo:
            q(19)      L(17)        0           -pi/2
            q(20)-pi   0            L(18)        0    ];
 else
     DH = [-q(12)      0          L(2)    pi/2    %-- Perna esquerda: S1 -> S6=S6'
            q(11)      0          L(3)    0
            q(10)      0          L(4)    0
            q(9)       0          L(5)    pi/2
            q(8)       0          L(6)    0
           -pi/2       0          0      -pi/2                      

            -q(7)+pi    0         -L(8)    0       %-- Anca: S6' -> S7

            -q(6)      -L(6)       0      -pi/2    %-- Perna esquerda: S7 -> S13
            q(5)+pi/2  0          L(5)    -pi/2
            q(4)       0          L(4)    0
            q(3)       0          L(3)    0
            q(2)       0          L(2)    pi/2
            q(1)       0          L(1)    0      

            -q(7)-pi    L(7)      -L(8)/2 -pi/2      %-- Tronco inferi:  S6' -> S14 
            -pi/2       0          L(9)    0         %--                 S14 -> S15
            -q(13)      0          L(10)   -pi/2      %--                 S15 -> S16
            q(14)      0          L(11)   0         %--                 S16 -> S17

            0          0          L(12)+L(13)  0    %-- Tronco/Cabeça:  S17 -> S18
            pi/2       0          0            pi/2 %--                 S18 -> S18' 
            q(15)      L(14)      0           -pi/2 %--                 S18'-> S19
            q(16)-pi/2 0          L(15)        0    %--                 S19 -> S20

            q(14)     -L(8)/2-L(16) L(11)+L(12)  pi   %-- Braço direito:
            q(19)      L(17)        0            pi/2
            q(20)-pi   0            L(18)        0

            q(14)      L(8)/2+L(16) L(11)+L(12)  0    %-- Braço esquerdo:
            q(17)      L(17)        0           -pi/2
            q(18)-pi   0            L(18)        0    ];
 end

%-- Matrizes de transformaçao Ai -----------------------------------------------------
 A(:,:,1) = [ 0  0  1  XYZRef(1)
              0 -1  0  XYZRef(2)
              1  0  0  L(1)+XYZRef(3) 
              0  0  0  1    ];
for i=1:size(DH,1),
     A(:,:,i+1) = [ cos(DH(i,1)) -sin(DH(i,1))*cos(DH(i,4))  sin(DH(i,1))*sin(DH(i,4))  DH(i,3)*cos(DH(i,1))
                    sin(DH(i,1))  cos(DH(i,1))*cos(DH(i,4)) -cos(DH(i,1))*sin(DH(i,4))  DH(i,3)*sin(DH(i,1))
                    0                          sin(DH(i,4))               cos(DH(i,4))  DH(i,2)
                    0             0                          0                          1  ]; 
 end   
 %--------------------------------------------------------------------------------end
