% vytvori objekty g1 a g2 popisujici geometrii lambda mikrostruktury pro
% software Comsol Multiphysics
orientace1
twins
elconsts

AB=[3,5,2,1,2];
CD=[1,5,2,1,2];

UB=U{AB(2)};
QAB=Q{AB(1),AB(2),AB(3),AB(4),AB(5)};
QCD=Q{CD(1),CD(2),CD(3),CD(4),CD(5)};
FAB=F{AB(1),AB(2),AB(3),AB(4),AB(5)};
FCD=F{CD(1),CD(2),CD(3),CD(4),CD(5)};

n12=n{AB(1),AB(2),AB(3)};
n22=m{AB(1),AB(2),AB(3),AB(4),AB(5)};
n13=rnull(FCD-QAB*UB);
n23=m{CD(1),CD(2),CD(3),CD(4),CD(5)};
F1=eye(3);
F2=FAB;
F3=FCD;
F4=QAB*UB;
postRot=eye(3);

Ci=std2fem(rotaceC(CI, postRot));
Cb=std2fem(rotaceC(CU{5}, postRot*QAB*S{5}'));
Cab=std2fem(rotaceC(CUab{1,3,2,2}, postRot*QAB*S{5}'*Qa{12}));
Ccd=std2fem(rotaceC(CUab{1,5,2,2}, postRot*QCD*S{5}'*Qa{12}));

typ = 'martenzit';
konzistence = 'ano';
referencni = 1;

body

pIx=points{1}(1,:); pBx=points{4}(1,:);
pIy=points{1}(2,:); pBy=points{4}(2,:);
pIz=points{1}(3,:); pBz=points{4}(3,:);

pABx=points{2}(1,:); pCDx=points{3}(1,:);
pABy=points{2}(2,:); pCDy=points{3}(2,:);
pABz=points{2}(3,:); pCDz=points{3}(3,:);

KLMNi=face3([pIx(1:2); pIx(4:-1:3)],[pIy(1:2); pIy(4:-1:3)], ...
    [pIz(1:2); pIz(4:-1:3)]);
KLK2L2i=face3([pIx(1:2); pIx(5:6)], [pIy(1:2); pIy(5:6)], ...
    [pIz(1:2); pIz(5:6)]);
MNM2N2i=face3([pIx(3:4); pIx(7:8)], [pIy(3:4); pIy(7:8)], ...
    [pIz(3:4); pIz(7:8)]);
K2L2PCPAi=face3([pIx(5:6); pIx(9:10)], [pIy(5:6); pIy(9:10)],  ...
    [pIz(5:6); pIz(9:10)]);
N2M2PCPAi=face3([pIx(8:-1:7); pIx(9:10)], [pIy(8:-1:7); pIy(9:10)], ...
    [pIz(8:-1:7); pIz(9:10)]);

L2e=points{1}(:,6)+(points{1}(:,10)-points{1}(:,7));
M2e=points{1}(:,7)+(points{1}(:,10)-points{1}(:,6));
LML2PAM2i=face3([pIx(2:3); L2e(1) M2e(1)], [pIy(2:3); L2e(2) M2e(2)], ...
    [pIz(2:3); L2e(3) M2e(3)]);

K2e=points{1}(:,5)+(points{1}(:,9)-points{1}(:,8));
N2e=points{1}(:,8)+(points{1}(:,9)-points{1}(:,5));
NKN2PCK2i=face3([pIx(4) pIx(1); N2e(1) K2e(1)], ...
    [pIy(4) pIy(1); N2e(2) K2e(2)],[pIz(4) pIz(1); N2e(3) K2e(3)]);

gI = geomcoerce('solid', {KLMNi, KLK2L2i, LML2PAM2i, MNM2N2i, ...
                          NKN2PCK2i, K2L2PCPAi, N2M2PCPAi});

K2L2PCPAab=face3([pABx(1:2); pABx(3:4)], [pABy(1:2); pABy(3:4)], ...
    [pABz(1:2); pABz(3:4)]);
A2B2PCPAab=face3([pABx(5:6); pABx(3:4)], [pABy(5:6); pABy(3:4)], ...
    [pABz(5:6); pABz(3:4)]);
A2B2K2L2ab=face3([pABx(5:6); pABx(1:2)], [pABy(5:6); pABy(1:2)], ...
    [pABz(5:6); pABz(1:2)]);
L2PAB2ab=face3([pABx(2) pABx(6); pABx(4) pABx(4)], ...
    [pABy(2) pABy(6); pABy(4) pABy(4)], [pABz(2) pABz(6); pABz(4) pABz(4)]);
K2PCA2ab=face3([pABx(1) pABx(5); pABx(3) pABx(3)], ...
    [pABy(1) pABy(5); pABy(3) pABy(3)], [pABz(1) pABz(5); pABz(3) pABz(3)]);

gAB = geomcoerce('solid', {A2B2PCPAab, K2L2PCPAab, A2B2K2L2ab, ...
                           L2PAB2ab, K2PCA2ab});


N2M2PCPAcd=face3([pCDx(1:2); pCDx(3:4)], [pCDy(1:2); pCDy(3:4)], ...
    [pCDz(1:2); pCDz(3:4)]);
D2C2PCPAcd=face3([pCDx(5:6); pCDx(3:4)], [pCDy(5:6); pCDy(3:4)], ...
    [pCDz(5:6); pCDz(3:4)]);
D2C2N2M2cd=face3([pCDx(5:6); pCDx(1:2)], [pCDy(5:6); pCDy(1:2)], ...
    [pCDz(5:6); pCDz(1:2)]);
M2PAC2cd=face3([pCDx(2) pCDx(6); pCDx(4) pCDx(4)], ...
    [pCDy(2) pCDy(6); pCDy(4) pCDy(4)], [pCDz(2) pCDz(6); pCDz(4) pCDz(4)]);
N2PCD2cd=face3([pCDx(1) pCDx(5); pCDx(3) pCDx(3)], ...
    [pCDy(1) pCDy(5); pCDy(3) pCDy(3)], [pCDz(1) pCDz(5); pCDz(3) pCDz(3)]);

gCD = geomcoerce('solid', {D2C2PCPAcd, N2M2PCPAcd, D2C2N2M2cd, ...
                           M2PAC2cd, N2PCD2cd});

ABCDb=face3([pBx(1:2); pBx(4:-1:3)], [pBy(1:2); pBy(4:-1:3)], ...
    [pBz(1:2); pBz(4:-1:3)]);
ABA2B2b=face3([pBx(1:2); pBx(5:6)], [pBy(1:2); pBy(5:6)], ...
    [pBz(1:2); pBz(5:6)]);
CDC2D2b=face3([pBx(3:4); pBx(7:8)], [pBy(3:4); pBy(7:8)], ...
    [pBz(3:4); pBz(7:8)]);
A2B2PCPAb=face3([pBx(5:6); pBx(9:10)], [pBy(5:6); pBy(9:10)], ...
    [pBz(5:6); pBz(9:10)]);
D2C2PCPAb=face3([pBx(8:-1:7); pBx(9:10)], [pBy(8:-1:7); pBy(9:10)], ...
    [pBz(8:-1:7); pBz(9:10)]);

B2e=points{4}(:,6)+(points{4}(:,10)-points{4}(:,7));
C2e=points{4}(:,7)+(points{4}(:,10)-points{4}(:,6));
BCB2PAC2b=face3([pBx(2:3); B2e(1) C2e(1)], [pBy(2:3); B2e(2) C2e(2)], ...
    [pBz(2:3); B2e(3) C2e(3)]);

A2e=points{4}(:,5)+(points{4}(:,9)-points{4}(:,8));
D2e=points{4}(:,8)+(points{4}(:,9)-points{4}(:,5));
DAD2PCA2b=face3([pBx(4) pBx(1); D2e(1) A2e(1)], ...
    [pBy(4) pBy(1); D2e(2) A2e(2)],[pBz(4) pBz(1); D2e(3) A2e(3)]);

gB = geomcoerce('solid', {ABCDb, ABA2B2b, CDC2D2b, A2B2PCPAb, ...
    D2C2PCPAb, BCB2PAC2b, DAD2PCA2b});

g1= geomcoerce('solid', {gI, gAB, gCD});
g2= gB;