function A = CinDir12dof( q,L,XYRef )

%-- Parametros de Denavit:Hartenberg -------------------------------------------------
 DH = [ q(1)       0     L(2)    pi/2
        q(2)       0     L(3)    0
        q(3)       0     L(4)    0
        q(4)       0     L(5)   -pi/2
        q(5)+pi/2  0     0       pi/2
        0          L(6)  0       0
        q(6)       L(7)  0       0
        0          0    -L(9)/2  0
        0          L(8)  0       0
        0          0    -L(9)    0
        0         -L(7)  0       0
        0         -L(6)  0       0
        q(7)       0     0      -pi/2
        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    ];        

%-- Matrizes de transformaçao Ai -----------------------------------------------------
 A(:,:,1) = [ 0  0  1  XYRef(1)
              0 -1  0  XYRef(2)
              1  0  0  L(1) 
              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   
 A(:,:,19) = [ 0 -sin(DH(18,1))  -cos(DH(18,1))  L(1)*cos(DH(18,1))
               0  cos(DH(18,1))  -sin(DH(18,1))  L(1)*sin(DH(18,1))
               1              0               0                   0
               0              0               0                   1 ];
 %--------------------------------------------------------------------------------end
