Mocto:={{1,0,1,-1},{0,1,1,1},{1,1,1,0},{-1,1,0,1}};
s:=1/Sqrt[2];

lambda:=1+Sqrt[2];

Octonacci[k_]:=If[k==1,1,If[k==2,2,2*Octonacci[k-1]+Octonacci[k-2]]];

Octonacci[4]

Id:={{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};

Minv[k_]:=(-1)^(k+1)*(Octonacci[k]*Mocto-Octonacci[k+1]*Id);

Projepar:=0.5*{{1,0,s,-s},{0,1,s,s},{s,s,1,0},{-s,s,0,1}};

Projeperp:=0.5*{{1,0,-s,s},{0,1,-s,-s},{-s,-s,1,0},{s,-s,0,1}};

ArHypCube:={{0,0,0,0},{1,0,0,0},{0,1,0,0},{0,0,1,0},{1,1,0,0},{1,0,1,0},{0,1,1,0},{1,1,1,0},{0,0,0,1},{1,0,0,1},{0,1,0,1},{0,0,1,1},{1,1,0,1},{1,0,1,1},{0,1,1,1},{1,1,1,1}};

gammak[l_,k_]:=Module[{ll=l},Do[AppendTo[ll,Minv[k].ArHypCube[[j]]],{j,1,16}];ll];

Proj0:={{0,0,0,0},{0,0,0,0},{0,0,1,0},{0,0,0,1}};

Projpar0:={{1,0,0,0},{0,1,0,0},{0,0,0,0},{0,0,0,0}};

Prod[x_,y_]:=x[[1]]*y[[2]]-x[[2]]*y[[1]];

Bar[a_,b_,c_,x_]:={Prod[b-x,c-x]/Prod[b-a,c-a],Prod[c-x,a-x]/Prod[b-a,c-a],Prod[a-x,b-x]/Prod[b-a,c-a]};
EnvConv[a_,b_,c_,x_]:=Module[{bar=Bar[a,b,c,x]},bar[[1]]≥0 && bar[[2]]≥0 && bar[[3]]≥0];

EnvConvStrict[a_,b_,c_,x_]:=Module[{bar=Bar[a,b,c,x]},bar[[1]]>0 && bar[[2]]>0 && bar[[3]]>0];

(* Essai avec k=3*)

g3:=gammak[{},3];

g3

pg3:={};

For[kk=1,kk<17,kk++,AppendTo[pg3,{(Proj0.(g3[[kk]]))[[3]],(Proj0.(g3[[kk]]))[[4]]}]];

ListPlot[PtsExt]

pg3

PtsExt:={{-2,5},{5,5},{10,0},{10,-7},{5,-12},{-2,-12},{-7,-7},{-7,0}};

InPoly3v2[{q1_,q2_,q3_,q4_}]:=Module[{t,q={q3,q4}},t=EnvConv[{0,0},PtsExt[[1]],PtsExt[[2]],q]||EnvConv[{0,0},PtsExt[[2]],PtsExt[[3]],q]||EnvConv[{0,0},PtsExt[[3]],PtsExt[[4]],q]||EnvConv[{0,0},PtsExt[[4]],PtsExt[[5]],q]||EnvConv[{0,0},PtsExt[[5]],PtsExt[[6]],q]||EnvConv[{0,0},PtsExt[[6]],PtsExt[[7]],q]||EnvConv[{0,0},PtsExt[[7]],PtsExt[[8]],q];t];

InPoly3v2Strict[{q1_,q2_,q3_,q4_}]:=Module[{t,q={q3,q4}},t=EnvConvStrict[{0,0},PtsExt[[1]],PtsExt[[2]],q]||EnvConvStrict[{0,0},PtsExt[[2]],PtsExt[[3]],q]||EnvConvStrict[{0,0},PtsExt[[3]],PtsExt[[4]],q]||EnvConvStrict[{0,0},PtsExt[[4]],PtsExt[[5]],q]||EnvConvStrict[{0,0},PtsExt[[5]],PtsExt[[6]],q]||EnvConvStrict[{0,0},PtsExt[[6]],PtsExt[[7]],q]||EnvConvStrict[{0,0},PtsExt[[7]],PtsExt[[8]],q];t];

Points3v2[l_,m1_,m2_,m3_,m4_]:=Module[{ll=l},Do[If[InPoly3v2[{q1,q2,q3,q4}],AppendTo[ll,lambda*lambda*lambda*{(Pinv.(Projepar.{q1,q2,q3,q4}))[[1]],(Pinv.(Projepar.{q1,q2,q3,q4}))[[2]]}]],{q1,0,m1},{q2,0,m2},{q3,0,m3},{q4,0,m4}];ll];

ListPlot[Points3v2[{},1,1,1,1]]

Voisins3v2[res_,l_]:=Module[{n=Length[l],d, r=res},Do[{d=Norm[l[[j]]-l[[jj]]];If[d==1 && j<jj,AppendTo[r,{{(Pinv.(Projepar.(l[[j]])))[[1]],(Pinv.(Projepar.(l[[j]])))[[2]]},{(Pinv.(Projepar.(l[[jj]])))[[1]],(Pinv.(Projepar.(l[[jj]])))[[2]]}}]]},{j,1,n}, {jj,1,n}];r];

VoisinsPerp[res_,l_]:=Module[{n=Length[l],d, r=res},Do[{d=Norm[l[[j]]-l[[jj]]];If[d==1 && j<jj,AppendTo[r,{{(Pinv.(Projeperp.(l[[j]])))[[3]],(Pinv.(Projeperp.(l[[j]])))[[4]]},{(Pinv.(Projeperp.(l[[jj]])))[[3]],(Pinv.(Projeperp.(l[[jj]])))[[4]]}}]]},{j,1,n}, {jj,1,n}];r];

AuxPVv2[m_,l_]:=Module[{ll=l},Do[If[InPoly3v2[{q1,q2,q3,q4}],AppendTo[ll,{q1,q2,q3,q4}]],{q1,0,m},{q2,0,m},{q3,0,m},{q4,0,m}];ll];

AuxPVv2Strict[m_,l_]:=Module[{ll=l},Do[If[InPoly3v2Strict[{q1,q2,q3,q4}],AppendTo[ll,{q1,q2,q3,q4}]],{q1,0,m},{q2,0,m},{q3,0,m},{q4,0,m}];ll];

vois5:=AuxPVv2[1,{}];

Tracer[l_]:=Module[{ll=Voisins3v2[{},l]},GraphPlot[Table[ll[[j,1]]-> ll[[j,2]],{j,1,Length[ll]}]]];

TracerPerp[l_]:=Module[{ll=VoisinsPerp[{},l]},GraphPlot[Table[ll[[j,1]]-> ll[[j,2]],{j,1,Length[ll]}]]];

Tracer[vois5]

TracerPerp[vois5]

vois11:=AuxPVv2[3,{}];

TracerPerp[vois11]