function c2=rotaceC(c1,P)
%Prepocita elasticke koeficienty pro material otoceny rotaci P
%Autorem tohoto skriptu je Ing. Hanus Seiner, Phd.

 % pokud neni system S2 normalizovan, normalizuje se :
 P(:,1)=P(:,1)./norm(P(:,1));
 P(:,2)=P(:,2)./norm(P(:,2));
 P(:,3)=P(:,3)./norm(P(:,3));

 if norm(P'*P-eye(3))>1e-12
  error('Zadany system P neni ortogonalni !')
 end

%--------------------------------------------------------------------------
%                   SESTAVENI TENZORU
%--------------------------------------------------------------------------

 for i=1:6
  for j=i:6

   if not(c1(i,j)==c1(j,i))
    error('Zadana matice elastickych koeficientu neni symetricka !');
   end

   if i<4 a=i; b=i;
   elseif i==4 a=2; b=3;
   elseif i==5 a=1; b=3;
   elseif i==6 a=1; b=2;
   end
   %----------------------------
   if j<4 d=j; e=j;
   elseif j==4 d=2; e=3;
   elseif j==5 d=1; e=3;
   elseif j==6 d=1; e=2;
   end

   % C je tenzor ctvrteho radu elastickych koeficientu
   C1(a,b,d,e)=c1(i,j);   C1(d,e,a,b)=c1(i,j);
   C1(b,a,d,e)=c1(i,j);   C1(d,e,b,a)=c1(i,j);
   C1(a,b,e,d)=c1(i,j);   C1(e,d,a,b)=c1(i,j);
   C1(b,a,e,d)=c1(i,j);   C1(e,d,b,a)=c1(i,j);

  end
 end
 %-------------------------------------------------------------------------
 %                   transformace tenzoru
 %-------------------------------------------------------------------------

 for i1=1:3;
  for i2=1:3;
   for i3=1:3;
    for i4=1:3;
     C2(i1,i2,i3,i4)=0;
     for j1=1:3;
      for j2=1:3;
       for j3=1:3;
        for j4=1:3;
         C2(i1,i2,i3,i4)=C2(i1,i2,i3,i4)+P(i1,j1)*P(i2,j2)*...
                         P(i3,j3)*P(i4,j4)*C1(j1,j2,j3,j4);
end; end; end; end; end; end; end; end

 %-------------------------------------------------------------------------
 %              a opetovne sestaveni matice elastickych koeficientu
 %-------------------------------------------------------------------------

 c2 = [
  C2(1,1,1,1) C2(1,1,2,2) C2(1,1,3,3) C2(1,1,2,3) C2(1,1,1,3) C2(1,1,1,2);
  C2(1,1,2,2) C2(2,2,2,2) C2(2,2,3,3) C2(2,2,2,3) C2(2,2,1,3) C2(2,2,1,2);
  C2(1,1,3,3) C2(2,2,3,3) C2(3,3,3,3) C2(3,3,2,3) C2(3,3,1,3) C2(3,3,1,2);
  C2(1,1,2,3) C2(2,2,2,3) C2(3,3,2,3) C2(2,3,2,3) C2(2,3,1,3) C2(2,3,1,2);
  C2(1,1,1,3) C2(2,2,1,3) C2(3,3,1,3) C2(2,3,1,3) C2(1,3,1,3) C2(1,3,1,2);
  C2(1,1,1,2) C2(2,2,1,2) C2(3,3,1,2) C2(2,3,1,2) C2(1,3,1,2) C2(1,2,1,2)];
end
