% do struktury 'points' ulozi souradnice bodu potrebnych k vykresleni
% mikrostruktury
clear O sa sb sc K L M N A B C D PO PC K2 L2 M2 N2 A2 B2 C2 D2 PA points pr;

O=[0,0,0]';

sa=dim_a*normc(cross(EF, AC));
sb=dim_b*normc(cross(BD, EF));
sc=dim_c*normc(cross(AC, BD));

K=O;        A=K+sc;
L=K+sb;     B=L+sc;
M=K+sa+sb;  C=M+sc;
N=K+sa;     D=N+sc;

PO=0.5*sa+0.5*sc+0.5*sb;

PC{1}=PO + ((AC'*(A-PO))/(AC'*cross(n22, n23)))*cross(n22, n23);
PC{2}=PO + ((AC'*(A-PO))/(AC'*cross(n12, n22)))*cross(n12, n22);
PC{3}=PO + ((AC'*(A-PO))/(AC'*cross(n13, n23)))*cross(n13, n23);
PC{4}=PO + ((AC'*(A-PO))/(AC'*cross(n13, n12)))*cross(n13, n12);

if strcmp(konzistence, 'ano')
 for i=1:4
  if i~=referencni
   PC{i}=PC{referencni};
  end
 end
 pr=PO-PC{referencni};
 n12=cross(pr, cross(pr, n12));
 n13=cross(pr, cross(pr, n13));
 n22=cross(pr, cross(pr, n22));
 n23=cross(pr, cross(pr, n23));
end

K2=prusecik(PC{1}, cross(n22, AC), K, sc);
L2=prusecik(K2, cross(n22, BD), L, sc);


N2=prusecik(PC{1}, cross(n23, AC), N, sc);
M2=prusecik(N2, cross(n23, BD), M, sc);

A2=prusecik(PC{4}, cross(n12, AC), A, sc);
B2=prusecik(A2, cross(n12, BD), B, sc);

D2=prusecik(PC{4}, cross(n13, AC), D, sc);
C2=prusecik(D2, cross(n13, BD), C, sc);

PA{1}=prusecik(L2, cross(n22, AC), M2, cross(n23, AC));
PA{2}=prusecik(B2, cross(n12, AC), L2, cross(n22, AC));
PA{3}=prusecik(C2, cross(n13, AC), M2, cross(n23, AC));
PA{4}=prusecik(B2, cross(n12, AC), C2, cross(n13, AC));

points{1}=[K L M N K2 L2 M2 N2 PC{1} PA{1} PO];
points{2}=[K2 L2 PC{2} PA{2} A2 B2 PO];
points{3}=[N2 M2 PC{3} PA{3} D2 C2 PO];
points{4}=[A B C D A2 B2 C2 D2 PC{4} PA{4} PO];

if strcmp(typ, 'martenzit')
 points{1}=F1*points{1};
 points{2}=F2*points{2};
 points{3}=F3*points{3};
 points{4}=F4*points{4};
 
 points{1}=points{1} + (points{referencni}(:,end)-points{1}(:,end))* ...
            ones(1, size(points{1},2));
 points{2}=points{2} + (points{referencni}(:,end)-points{2}(:,end))* ...
            ones(1, size(points{2},2));
 points{3}=points{3} + (points{referencni}(:,end)-points{3}(:,end))* ...
            ones(1, size(points{3},2));
 points{4}=points{4} +  (points{referencni}(:,end)-points{4}(:,end))* ...
            ones(1, size(points{4},2));
end

points{1}=postRot*points{1};
points{2}=postRot*points{2};
points{3}=postRot*points{3};
points{4}=postRot*points{4};

clear O sa sb sc K L M N A B C D PO PC K2 L2 M2 N2 A2 B2 C2 D2 PA pr;