function C = JointCoordinates( q,L )

 %-- Definition of constants & variables ----------------------------------
  l0 = L(1); l1 = L(2); l2 = L(3);
  ang1 = q(1); ang2 = q(2); ang3 = q(3);
 %-- Original cylinder ----------------------------------------------------
  [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))];
 %-- Joint#1: homogeneous transformation ----------------------------------
  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,:)))];

 %-- Joint#2: homogeneous transformation ----------------------------------
  T2 = T1*[ cos(ang1)  0  sin(ang1) 0
            sin(ang1)  0 -cos(ang1) 0
            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,:)))];
 %-- Joint#3: homogeneous transformation ----------------------------------
  T3 = T2*[ cos(ang2) -sin(ang2) 0 l1*cos(ang2)
            sin(ang2)  cos(ang2) 0 l1*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,:)))];
 %-- Output matrix --------------------------------------------------------
  C(:,:,1) = C1;
  C(:,:,2) = C2;
  C(:,:,3) = C3;
 %----------------------------------------------------------------------end