SetDirectory[NotebookDirectory[]];

delkavozovky=1000;

pocetpruhu=2;

sirkapruhu=3;

a=24.;

b=2*sirkapruhu;

c=0.5;

L=0.75;

U0=0.4;

U1=0.6;

REI=0.3;

h=5.;

delta=0;

fm=0.6;

tokuprava=1;

bc=b+c;

deltar=((delta*Pi)/180);

bodydelka=Piecewise[{{10,a≤30}},Ceiling[(a/3.)]];

bodysirka=3*pocetpruhu;

Droz=(a/bodydelka);

d=(b/bodysirka);

souradnicex=Table[x,{x,Droz/2.,bodydelka*Droz,Droz}];

souradnicey=Table[y+c,{y,d/2.,bodysirka*d,d}];

dvojce=Tuples[{souradnicey,souradnicex}];

souradnice=Table[{dvojce[[i,2]],dvojce[[i,1]]},{i,1,bodydelka*bodysirka,1}];

souradniceopacnyy=Table[y+c+pocetpruhu*sirkapruhu,{y,d/2.,bodysirka*d/pocetpruhu,d}];

souradnicestejnyy=Table[c-y,{y,d/2.,bodysirka*d/pocetpruhu,d}];

souradniceopacny=Tuples[{souradnicex,souradniceopacnyy}];

souradnicestejny=Tuples[{souradnicex,souradnicestejnyy}];

rpodklad=Import["rtabulka.xlsx"][[1]];

rhodnoty=Flatten[Table[{{rpodklad[[1,j]],rpodklad[[i,1]]},rpodklad[[i,j]]},{i,2,Length[rpodklad]},{j,2,Length[First[rpodklad]]}],1];

rfunkce=Interpolation[rhodnoty];

epsilonfunkce[x_,y_]:=ArcTan[(x/y)];

nvpravo=Table[Floor[(12*h-(a-souradnice[[i,1]]))/a]+Piecewise[{{1,(a-souradnice[[i,1]])<12*h}},0],{i,1,bodydelka*bodysirka,1}];

nvlevo=Table[Floor[Abs[5*h-souradnice[[i,1]]]/a]+Piecewise[{{1,souradnice[[i,1]]<5*h}},0],{i,1,bodydelka*bodysirka,1}];

nvpravoopacny=Table[Floor[(12*h-(a-souradniceopacny[[i,1]]))/a]+Piecewise[{{1,(a-souradniceopacny[[i,1]])<12*h}},0],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

nvlevoopacny=Table[Floor[Abs[5*h-souradniceopacny[[i,1]]]/a]+Piecewise[{{1,souradniceopacny[[i,1]]<5*h}},0],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

nvpravostejny=Table[Floor[(12*h-(a-souradnicestejny[[i,1]]))/a]+Piecewise[{{1,(a-souradnicestejny[[i,1]])<12*h}},0],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

nvlevostejny=Table[Floor[Abs[5*h-souradnicestejny[[i,1]]]/a]+Piecewise[{{1,souradnicestejny[[i,1]]<5*h}},0],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

ubodyfunkce[x_,y_,z_,v_,w_]:=Table[(Sqrt[(x^2)+(((y+o*z))^2)]),{o,v,w,1}];

uvpravo=Table[ubodyfunkce[souradnice[[i,2]],a-souradnice[[i,1]],a,0,nvpravo[[i]]-1],{i,1,bodydelka*bodysirka,1}];

uvlevo=Table[ubodyfunkce[souradnice[[i,2]],souradnice[[i,1]],a,0,nvlevo[[i]]-1],{i,1,bodydelka*bodysirka,1}];

uvpravoopacny=Table[ubodyfunkce[souradniceopacny[[i,2]],a-souradniceopacny[[i,1]],a,0,nvpravoopacny[[i]]-1],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

uvlevoopacny=Table[ubodyfunkce[souradniceopacny[[i,2]],souradniceopacny[[i,1]],a,0,nvlevoopacny[[i]]-1],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

uvpravostejny=Table[ubodyfunkce[souradnicestejny[[i,2]],a-souradnicestejny[[i,1]],a,0,nvpravoopacny[[i]]-1],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

uvlevostejny=Table[ubodyfunkce[souradnicestejny[[i,2]],souradnicestejny[[i,1]],a,0,nvlevoopacny[[i]]-1],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

epsilonmat=Table[epsilonfunkce[Join[uvpravo[[i]],uvlevo[[i]]],h],{i,1,bodydelka*bodysirka,1}];

epsilonrastr=Table[epsilonfunkce[(Sqrt[((souradnice[[i,1]])^2)+((souradnice[[i,2]])^2)]),h],{i,1,bodydelka*bodysirka,1}];

epsilonmatopacny=Table[epsilonfunkce[Join[uvpravoopacny[[i]],uvlevoopacny[[i]]],h],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

epsilonmatstejny=Table[epsilonfunkce[Join[uvpravostejny[[i]],uvlevostejny[[i]]],h],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

beta=Table[(180/Pi)*ArcCos[((souradnice[[i,1]]+60)*Piecewise[{{-(j-nvpravo[[i]]-1)*a-60,j>nvpravo[[i]]}},j*a-60]+(souradnice[[i,2]]-c+(2*Ceiling[((i/bodydelka)/3)]-1)*(sirkapruhu/2))*(-souradnice[[i,2]]))/(√((((souradnice[[i,1]]+60))^2)+(((souradnice[[i,2]]-c+(2*Ceiling[((i/bodydelka)/3)]-1)*(sirkapruhu/2)))^2))*√((((Piecewise[{{-(j-nvpravo[[i]]-1)*a-60,j>nvpravo[[i]]}},j*a-60]))^2)+(((-souradnice[[i,2]]))^2)))],{i,1,bodydelka*bodysirka,1},{j,0,nvpravo[[i]]+nvlevo[[i]]-1,1}];

hvyzplochy=0.3;

dvyzplochy=0.1;

A=((Pi*(dvyzplochy^2))/4.)*Cos[((85.*Pi)/180.)]+hvyzplochy*dvyzplochy*Cos[((85.*Pi)/180.)];

Ay=23;

xd=2.75*Abs[h-1.5];

nlu=Table[Count[Table[(Sqrt[((((Sqrt[((((((2n-1)*sirkapruhu)/2)+c))^2)+(((xd+i*a))^2)])))^2)+(((h-1.5))^2)]),{i,0,Floor[((500.-xd)/a)],1}],(x_/;x<5*h)],{n,1,pocetpruhu,1}];

alfafunkce[x_,y_]:=ArcSin[(x/y)];

dLkPfunkce[x_,y_]:=(Sqrt[(x^2)+(y^2)]);

ufTI=Table[ubodyfunkce[c+(((2*n-1)*sirkapruhu)/2),xd,a,0,nlu[[n]]-1],{n,1,pocetpruhu,1}];

epsilonfTI=Table[epsilonfunkce[ufTI[[n]],h-1.5],{n,1,pocetpruhu,1}];

alfafTI=Table[alfafunkce[c+(((2*n-1)*sirkapruhu)/2),ufTI[[n]]],{n,1,pocetpruhu,1}];

dfTI=Table[dLkPfunkce[ufTI[[n]],h-1.5],{n,1,pocetpruhu,1}];

cr=((Cplane*Pi)/180);

epsilon=deltar+gama;

u=Round[h*Abs[Tan[epsilon]],0.0001];

bodkolmice=Round[Piecewise[{{u*Sin[cr],0≤cr<(Pi/2)},{u*Sin[Pi-cr],(Pi/2)≤cr<Pi},{u*Sin[cr-Pi],Pi≤cr<((3*Pi)/2)}},u*Sin[2*Pi-cr]],0.0001];

svetlokolmice=(Sqrt[(u^2)-(bodkolmice^2)]);

hranicniuhel1=ArcTan[(bc/a)];

hranicniuhel2=Pi-hranicniuhel1;

hranicniuhelopacny1=ArcTan[((bc+sirkapruhu)/a)];

hranicniuhelopacny2=Pi-hranicniuhelopacny1;

hranicniuhelstejny1=ArcTan[((sirkapruhu-c)/a)]+Pi;

hranicniuhelstejny2=2*Pi-ArcTan[((sirkapruhu-c)/a)];

l=Piecewise[{{(a/(Cos[cr])),0≤cr≤hranicniuhel1},{(bc/(Sin[cr])),hranicniuhel1<cr<=(Pi/2)},{(bc/(Sin[Pi-cr])),(Pi/2)<cr≤hranicniuhel2},{(a/(Cos[Pi-cr])),hranicniuhel2<cr<=Pi}},0];

lopacny=Piecewise[{{(a/(Cos[cr])),0≤cr≤hranicniuhelopacny1},{((bc+sirkapruhu)/(Sin[cr])),hranicniuhelopacny1<cr<=(Pi/2)},{((bc+sirkapruhu)/(Sin[Pi-cr])),(Pi/2)<cr≤hranicniuhelopacny2},{(a/(Cos[Pi-cr])),hranicniuhelopacny2<cr<=Pi}},0];

lstejny=Piecewise[{{(a/(Cos[cr-Pi])),Pi≤cr≤hranicniuhelstejny1},{((sirkapruhu-c)/(Sin[cr-Pi])),hranicniuhelstejny1<cr<=((3*Pi)/2)},{((sirkapruhu-c)/(Sin[2*Pi-cr])),((3*Pi)/2)<cr≤hranicniuhelstejny2},{(a/(Cos[2*Pi-cr])),hranicniuhelstejny2<cr≤2*Pi}},0];

uhel=-1;

GIrastr=If[MemberQ[epsilonrastr,85*(Pi/180)]==True,{(Subscript[Inez, Position[epsilonrastr,85*(Pi/180)]])*(A^(-0.5))≤500},{}];

fTI=Max[Flatten[Table[(65*((∑_(p=1)^(nlu[[n]]))Piecewise[{{9.86*(1+((((Ay/66.4)))^4))*((((Subscript[InezfTI, n])*fm*Sin[epsilonfTI[[n,p]]]*(1+Cos[alfafTI[[n,p]]]))/((dfTI[[n,p]])^2))/(((ArcCos[((((p-1)*a+xd)*Cos[((uhel*Pi)/180)]+(h-1.5)*Sin[((uhel*Pi)/180)])/(Sqrt[((((p-1)*a+xd))^2)+(((c+(((2n-1)*sirkapruhu)/2)))^2)+(((h-1.5))^2)]))]*(180/Pi)))^2)),1.5*(Pi/180)<ArcCos[((((p-1)*a+xd)*Cos[((uhel*Pi)/180)]+(h-1.5)*Sin[((uhel*Pi)/180)])/(Sqrt[((((p-1)*a+xd))^2)+(((c+(b/2)))^2)+(((h-1.5))^2)]))]≤60*(Pi/180)},{((1/((dfTI[[n,p]])^2))(Subscript[InezfTI, n])*fm*Sin[epsilonfTI[[n,p]]]*(1+Cos[alfafTI[[n,p]]]))*((10/(((ArcCos[((((p-1)*a+xd)*Cos[((uhel*Pi)/180)]+(h-1.5)*Sin[((uhel*Pi)/180)])/(Sqrt[((((p-1)*a+xd))^2)+(((c+(((2n-1)*sirkapruhu)/2)))^2)+(((h-1.5))^2)]))]*(180/Pi)))^3))+(5/(((ArcCos[(((p-1)*a+xd)*Cos[((uhel*Pi)/180)]+(h-1.5)*Sin[((uhel*Pi)/180)])/(√(((((p-1)*a+xd))^2)+(((c+(((2n-1)*sirkapruhu)/2)))^2)+(((h-1.5))^2)))]*(180/Pi)))^2))*(1+((((Ay/62.5)))^4))),0.1*(Pi/180)<ArcCos[ArcCos[(((p-1)*a+xd)*Cos[((uhel*Pi)/180)]+(h-1.5)*Sin[((uhel*Pi)/180)])/(√(((((p-1)*a+xd))^2)+(((c+(((2n-1)*sirkapruhu)/2)))^2)+(((h-1.5))^2)))]*(180/Pi)]≤1.5*(Pi/180)}},0])/(((((∑_(m=1)^(bodydelka*bodysirka))(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))(1/(h^2))(Subscript[Inez, m])*0.9*(10^(-4))*rfunkce[beta[[m,k]],Tan[epsilonmat[[m,k]]]])/(bodydelka*bodysirka)))^1)),{n,1,pocetpruhu,1}]]]≤15;

nezapornarovnice=Join[Table[(Subscript[Inez, i])>0, {i,1,bodydelka*bodysirka,1}],Table[(Subscript[InezfTI, i])>0, {i,1,pocetpruhu,1}]];

rovnosti=Flatten[Table[If[i==j,Unevaluated@Sequence[],If[Sort[epsilonmat[[i]]]==Sort[epsilonmat[[j]]],(Subscript[Inez, i])==(Subscript[Inez, j]),Unevaluated@Sequence[]]], {i,1,bodydelka*bodysirka/2,1}, {j,1,bodydelka*bodysirka,1}]];

rovnomernostpruh=Table[U1≤(Min[Table[(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))(1/(h^2))(Subscript[Inez, m])*fm*(10^(-4))*rfunkce[beta[[m,k]],Tan[epsilonmat[[m,k]]]],{m,bodydelka+1+3*bodydelka*(n-1),bodydelka+1+3*bodydelka*(n-1)+bodydelka-1,1}]]/Max[Table[(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))(1/(h^2))(Subscript[Inez, m])*fm*(10^(-4))*rfunkce[beta[[m,k]],Tan[epsilonmat[[m,k]]]],{m,bodydelka+1+3*bodydelka*(n-1),bodydelka+1+3*bodydelka*(n-1)+bodydelka-1,1}]]),{n,1,pocetpruhu,1}];

rovnomernost=U0≤(Min[Table[(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))(1/(h^2))(Subscript[Inez, m])*fm*(10^(-4))*rfunkce[beta[[m,k]],Tan[epsilonmat[[m,k]]]],{m,1,bodydelka*bodysirka,1}]]/((∑_(m=1)^(bodydelka*bodysirka))(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))(1/(h^2))(Subscript[Inez, m])*fm*(10^(-4))*rfunkce[beta[[m,k]],Tan[epsilonmat[[m,k]]]])/(bodydelka*bodysirka));

prumernyjas=L≤((∑_(m=1)^(bodydelka*bodysirka))(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))(((Subscript[Inez, m])*fm*(10^(-4))*rfunkce[beta[[m,k]],Tan[epsilonmat[[m,k]]]])/(h^2)))/(bodydelka*bodysirka);

rovnice=Join[{prumernyjas},rovnomernostpruh,{rovnomernost},{fTI},GIrastr,nezapornarovnice,rovnosti];

reseni=FindInstance[rovnice,Join[Table[(Subscript[Inez, m]),{m,1,bodydelka*bodysirka,1}],Table[(Subscript[InezfTI, m]),{m,1,pocetpruhu,1}]],Reals];

resenihodnoty=Table[(Subscript[Inez, i])/.reseni[[1,i]],{i,1,bodydelka*bodysirka,1}];

prumerrastropacny=(((∑_(m=bodydelka*bodysirka*(1-(1/pocetpruhu))+1)^(bodydelka*bodysirka))(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))((resenihodnoty[[m]]*fm*((Cos[epsilonmat[[m,k]]])^3))/(h^2)))/((bodydelka*bodysirka)/pocetpruhu));

prumerrastrstejny=(((∑_(m=1)^(bodydelka*bodysirka/pocetpruhu))(∑_(k=1)^(nvpravo[[m]]+nvlevo[[m]]))((resenihodnoty[[m]]*fm*((Cos[epsilonmat[[m,k]]])^3))/(h^2)))/((bodydelka*bodysirka)/pocetpruhu));

osvetlenostokoliopacny=REI≤((∑_(m=1)^(bodydelka*bodysirka/pocetpruhu))((∑_(k=1)^(nvpravoopacny[[m]]+nvlevoopacny[[m]]))(1/(h^2))(Subscript[Inez, m])*fm*((Cos[epsilonmatopacny[[m,k]]])^3)))/(bodydelka*bodysirka/pocetpruhu)/prumerrastropacny;

osvetlenostokolistejny=REI≤(1/(bodydelka*bodysirka/pocetpruhu))((∑_(m=1)^(bodydelka*bodysirka/pocetpruhu))((∑_(k=1)^(nvpravostejny[[m]]+nvlevostejny[[m]]))(1/(h^2))(Subscript[Inez, m])*fm*((Cos[epsilonmatstejny[[m,k]]])^3)))/prumerrastrstejny;

rovnomernostopacny=0.3<Min[Flatten[Table[(∑_(k=1)^(nvpravoopacny[[m]]+nvlevoopacny[[m]]))(((Subscript[Inez, m])*fm*((Cos[epsilonmatopacny[[m,k]]])^3))/(h^2)),{m,1,bodydelka*bodysirka/pocetpruhu,1}]]]/Max[Flatten[Table[(∑_(k=1)^(nvpravoopacny[[m]]+nvlevoopacny[[m]]))(((Subscript[Inez, m])*fm*((Cos[epsilonmatopacny[[m,k]]])^3))/(h^2)),{m,1,bodydelka*bodysirka/pocetpruhu,1}]]];

rovnomernoststejny=0.3<Min[Flatten[Table[(∑_(k=1)^(nvpravostejny[[m]]+nvlevostejny[[m]]))(((Subscript[Inez, m])*fm*((Cos[epsilonmatstejny[[m,k]]])^3))/(h^2)),{m,1,bodydelka*bodysirka/pocetpruhu,1}]]]/Max[Flatten[Table[(∑_(k=1)^(nvpravostejny[[m]]+nvlevostejny[[m]]))(((Subscript[Inez, m])*fm*((Cos[epsilonmatstejny[[m,k]]])^3))/(h^2)),{m,1,bodydelka*bodysirka/pocetpruhu,1}]]];

reseniopacny=Table[(Subscript[Inez, i])/.FindInstance[Join[{osvetlenostokoliopacny},{rovnomernostopacny}],Table[(Subscript[Inez, i]),{i,1,bodydelka*bodysirka/pocetpruhu,1}],Reals][[1,i]],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

resenistejny=Table[(Subscript[Inez, i])/.FindInstance[Join[{osvetlenostokolistejny},{rovnomernoststejny}],Table[(Subscript[Inez, i]),{i,1,bodydelka*bodysirka/pocetpruhu,1}],Reals][[1,i]],{i,1,bodydelka*bodysirka/pocetpruhu,1}];

vysledkyrastr=Table[{souradnice[[i,1]],souradnice[[i,2]],resenihodnoty[[i]]},{i,1,bodydelka*bodysirka,1}];

vysledkyopacny=Table[{souradniceopacny[[i,1]],souradniceopacny[[i,2]],reseniopacny[[i]]},{i,1,bodydelka*bodysirka/pocetpruhu,1}];

vysledkystejny=Table[{souradnicestejny[[i,1]],souradnicestejny[[i,2]],resenistejny[[i]]},{i,1,bodydelka*bodysirka/pocetpruhu,1}];

index=If[gama≥0,Flatten[Position[Table[(Sqrt[(((svetlokolmice-vysledkyrastr[[i,1]]))^2)+(((bodkolmice-vysledkyrastr[[i,2]]))^2)]),{i,1,bodydelka*bodysirka,1}],Min[Flatten[Table[(Sqrt[(((svetlokolmice-vysledkyrastr[[i,1]]))^2)+(((bodkolmice-vysledkyrastr[[i,2]]))^2)]),{i,1,bodydelka*bodysirka,1}]]]]][[1]]];

indexopacny=If[gama≥0,Flatten[Position[Table[(Sqrt[(((svetlokolmice-vysledkyopacny[[i,1]]))^2)+(((bodkolmice-vysledkyopacny[[i,2]]))^2)]),{i,1,bodydelka*bodysirka/pocetpruhu,1}],Min[Flatten[Table[(Sqrt[(((svetlokolmice-vysledkyopacny[[i,1]]))^2)+(((bodkolmice-vysledkyopacny[[i,2]]))^2)]),{i,1,bodydelka*bodysirka/pocetpruhu,1}]]]]][[1]]];

indexstejny=If[gama≥0,Flatten[Position[Table[(Sqrt[(((svetlokolmice-vysledkystejny[[i,1]]))^2)+(((bodkolmice-vysledkystejny[[i,2]]))^2)]),{i,1,bodydelka*bodysirka/pocetpruhu,1}],Min[Flatten[Table[(Sqrt[(((svetlokolmice-vysledkystejny[[i,1]]))^2)+(((bodkolmice-vysledkystejny[[i,2]]))^2)]),{i,1,bodydelka*bodysirka/pocetpruhu,1}]]]]][[1]]];

Quiet[fce=If[gama≥0,Piecewise[{{Piecewise[{{{0},epsilon>ArcTan[(lopacny/h)]},{{vysledkyopacny[[indexopacny,3]]},ArcTan[(l/h)]<epsilon≤ArcTan[(lopacny/h)]},{{vysledkystejny[[indexstejny,3]]},bodkolmice<c}},{vysledkyrastr[[index,3]]}],Pi≥cr≥0}},Piecewise[{{{0},epsilon>ArcTan[(lstejny/h)]}},{vysledkystejny[[indexstejny,3]]}]]]];

roviny=Table[o,{o,0,360,0.5}];

stupne=Prepend[Table[p,{p,0,90,0.5}],""];

svitivosti=Table[fce[[1]]*tokuprava,{gama,0,Pi/2,((0.5*Pi)/180)},{Cplane,0,360,0.5}];

data=N[MapThread[Prepend,{Prepend[svitivosti,roviny],stupne}]];

Export["jasy_diplomka.xlsx",data,"XLSX"];