function [C1,C2,C3,C4,C5] = CoordJuntas( ang1,ang2,ang3,ang4,ang5,l0,l1,l2,l3,l4,l5 )

%-- Definiçao do cilindro original ------------------------------
[X,Y,Z] = cylinder(1,100);
X = 0.01*X; Y = 0.01*Y; Z = 0.1*(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))];

%-- Transformaçao homogenea -------------------------------------
T1 = [ 0  0 1 0
       0 -1 0 0
       1  0 0 l0
       0  0 0 1 ];
C1([1 3 5 7],:) = T1*[Pcyl(1,:); Pcyl(3,:); Pcyl(5,:); ones(1,length(Pcyl(1,:)))];
C1([2 4 6 7],:) = T1*[Pcyl(2,:); Pcyl(4,:); Pcyl(6,:); ones(1,length(Pcyl(1,:)))];

T2 = T1*[ cos(ang1)  0  sin(ang1) l1*cos(ang1)
          sin(ang1)  0 -cos(ang1) l1*sin(ang1)
          0          1  0         0
          0          0  0         1           ];
C2([1 3 5 7],:) = T2*[Pcyl(1,:); Pcyl(3,:); Pcyl(5,:); ones(1,length(Pcyl(1,:)))];
C2([2 4 6 7],:) = T2*[Pcyl(2,:); Pcyl(4,:); Pcyl(6,:); ones(1,length(Pcyl(1,:)))];

T3 = T2*[ cos(ang2) -sin(ang2) 0 l2*cos(ang2)
          sin(ang2)  cos(ang2) 0 l2*sin(ang2)
          0          0         1 0
          0          0         0 1           ];
C3([1 3 5 7],:) = T3*[Pcyl(1,:); Pcyl(3,:); Pcyl(5,:); ones(1,length(Pcyl(1,:)))];
C3([2 4 6 7],:) = T3*[Pcyl(2,:); Pcyl(4,:); Pcyl(6,:); ones(1,length(Pcyl(1,:)))];

T4 = T3*[ cos(ang3) -sin(ang3) 0 l3*cos(ang3)
          sin(ang3)  cos(ang3) 0 l3*sin(ang3)
          0          0         1 0
          0          0         0 1           ];
C4([1 3 5 7],:) = T4*[Pcyl(1,:); Pcyl(3,:); Pcyl(5,:); ones(1,length(Pcyl(1,:)))];
C4([2 4 6 7],:) = T4*[Pcyl(2,:); Pcyl(4,:); Pcyl(6,:); ones(1,length(Pcyl(1,:)))];

T5 = T4*[ cos(ang4)  0 -sin(ang4) l4*cos(ang4)
          sin(ang4)  0  cos(ang4) l4*sin(ang4)
          0         -1  0         0
          0          0  0         1           ];
C5([1 3 5 7],:) = T5*[Pcyl(1,:); Pcyl(3,:); Pcyl(5,:); ones(1,length(Pcyl(1,:)))];
C5([2 4 6 7],:) = T5*[Pcyl(2,:); Pcyl(4,:); Pcyl(6,:); ones(1,length(Pcyl(1,:)))];
