(* Two spheres, or other shapes, of opposite exactly overlap.  Plotting is impossible unless we use the Pfaffian.  *)

(*Pfaffian code from Harvard postdoc Everett You who addapted C/FORTRAN code created by R. W. Cherng for Mathematica*)
BeginPackage["Pfaffian`"];
Pf::usage="Pf[A] gives the pfaffian of the skew symmetric A.";
Begin["`Private`"];
Pf[A_]:=Switch[Length[A],0,1,_?OddQ,0,_?EvenQ,xPf[A,1]];
xPf[A_,p0_]:=Module[{A0,n,pivot,sign=1,A1,p1},n=Length[A]/2;
If[n≠1,A0=A;
pivot=First[Ordering[Normal[Abs[A0[[2 n-1,All]]]],-1]];
If[pivot≠2 n,A0[[{pivot,2 n},All]]=A0[[{2 n,pivot},All]];
A0[[All,{pivot,2 n}]]=A0[[All,{2 n,pivot}]];
sign=-1;];
p1=A0[[2 n-1,2 n]];
A1=p1 A0[[1;;2 n-2,1;;2 n-2]];
A1+=(#-Transpose[#])&@Outer[Times,A0[[1;;2 n-2,2 n]],A0[[1;;2 n-2,2 n-1]]];
A1/=p0;
sign xPf[A1,p1],A[[1,2]]]];
End[];
EndPackage[];

sigma1 = {{0,1}, {1,0}};

sigma2 = {{0,-I},{I,0}};

sigma3 = {{1,0},{0,-1}};

sig={{0,-1},{1,0}};

sig1={{0,1},{-1,0}};

Z=(KroneckerProduct[sig, IdentityMatrix[2]] );

MatrixForm[Z];

Q =(KroneckerProduct[IdentityMatrix[4],IdentityMatrix[2]]+KroneckerProduct[-sigma2,Z] );

MatrixForm[Q];

X={{0,1-2*s,0,s},{1-2*s,0,-s,0},{0,-s,0,1-2*s},{s,0,1-2*s,0}};

MatrixForm[X]

Y={{0,-I,0,0},{I,0,0,0},{0,0,0,I},{0,0,-I,0}};

MatrixForm[Y]

Z={{1-s,0,0,0},{0,-1+s,0,0},{0,0,1-s,0},{0,0,0,-1+s}};

MatrixForm[Z]

loclzr = KroneckerProduct[sigma1, X- x*IdentityMatrix[4]] + 
KroneckerProduct[sigma2,Y-y*IdentityMatrix[4]]+ 
KroneckerProduct[sigma3, Z-z*IdentityMatrix[4]] ;

MatrixForm[loclzr]

loclzrSkew = Simplify[I*(1/2)*ConjugateTranspose[Q].loclzr.Q];

MatrixForm[loclzrSkew]

archpoly = FullSimplify[Pf[loclzrSkew]]

step = 1/6;

plots=ParallelTable[ContourPlot3D[archpoly== 0, {x,-1.0,1.0}, {y,-1.0, 1.0}, {z, -1.0,1.0},Contours->{{1,LightBlue}},PlotPoints->100,ViewPoint->{18,-14,6}],{s,0,3/6,step}]

Export["ClassAIIspherePfaff0_6.eps",plots[[1]],ImageSize->2.5*72];

Export["ClassAIIspherePfaff1_6.eps",plots[[2]],ImageSize->2.5*72];

Export["ClassAIIspherePfaff2_6.eps",plots[[3]],ImageSize->2.5*72];

Export["ClassAIIspherePfaff3_6.eps",plots[[4]],ImageSize->2.5*72];