function [P,C,F] = CoordJuntas( Ai,XYRef )

%-- Definiçao do cilindro original ------------------------------------------------
 [X,Y,Z] = cylinder(1,100);
 X = 0.01*X; Y = 0.01*Y; Z = 0.05*(Z-0.5);
 X1 = X(1,:); Y1 = Y(1,:); Z1 = Z(1,:);
 X2 = X(2,:); Y2 = Y(2,:); Z2 = Z(2,:);
 Pcyl = [X1;X2;Y1;Y2;Z1;Z2;ones(1,length(X1))];

%-- Posiçao das juntas ------------------------------------------------------------ 
 T = [ 1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1];
 j=1; P(j,:) = [XYRef(1) XYRef(2) 0]; j=j+1;
 for i=1:size(Ai,3),         %-- Junta m ------------------------------------------
     T = T*Ai(:,:,i);
     if i == 8,  T_aux = T; end    
     if i ~= 6 & i ~= 14, P(j,:) = T(1:3,4)'; j = j+1; end
     if i == 10, T = T_aux; end 
 end
%-- Coordenadas dos cilindros ----------------------------------------------------- 
 T = [ 1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1];
 j=1;
 for i=1:size(Ai,3)-1,         %-- Junta m ----------------------------------------
     if i <= 8 | i >= 11,
         T = T*Ai(:,:,i); 
     else 
         continue
     end
     if i ~= 6 & i ~= 8 & i ~= 11 & i ~= 13,
        Cj([1 3 5 7],:) = T*[Pcyl(1,:); Pcyl(3,:); Pcyl(5,:); ones(1,length(Pcyl(1,:)))];
        Cj([2 4 6 7],:) = T*[Pcyl(2,:); Pcyl(4,:); Pcyl(6,:); ones(1,length(Pcyl(1,:)))];
        C(:,:,j) = Cj;  j=j+1;
     end
 end
%-- Elevar cilindro da anca -------------------------------------------------------
 C(5,:,6) = C(5,:,6)+0.05*0.5; C(6,:,6) = C(6,:,6)+0.05*0.5;
 C(5,:,7) = C(5,:,7)+0.05*0.5; C(6,:,7) = C(6,:,7)+0.05*0.5;
%-- Orientacao do pe livre -------------------------------------------------------- 
 T = T*Ai(:,:,19);
 F1 = [ -0.075  0.075  0.075 -0.075 %-- Top XY
        -0.035 -0.035  0.035  0.035
             0      0      0      0
             1      1      1      1 ]; F1 = T*F1;

 F2 = [  0.075  0.075  0.075  0.075 %-- YZ,X+
        -0.035  0.035  0.035 -0.035
             0      0  -0.02  -0.02 
             1      1      1      1 ]; F2 = T*F2;
      
 F3 = [ -0.075 -0.075 -0.075 -0.075 %-- YZ, X-
         0.035 -0.035 -0.035  0.035
             0      0  -0.02  -0.02
             1      1      1      1 ]; F3 = T*F3;
     
 F4 = [  0.075 -0.075 -0.075  0.075 %-- XZ, Y+
         0.035  0.035  0.035  0.035
             0      0  -0.02  -0.02
             1      1      1      1 ]; F4 = T*F4;
     
 F5 = [ -0.075  0.075  0.075 -0.075 %-- XZ, Y-
        -0.035 -0.035 -0.035 -0.035
             0      0  -0.02  -0.02
             1      1      1      1 ]; F5 = T*F5;

 F(1:3,:,1) = F1(1:3,:);  F(1:3,:,2) = F2(1:3,:); 
 F(1:3,:,3) = F3(1:3,:);  F(1:3,:,4) = F4(1:3,:); F(1:3,:,5) = F5(1:3,:);
%-------------------------------------------------------------------------------end