function [T] = TransPlanDesp(P,N,l,ldi,angc2,angtri2,angpent,x,y,z)
%Função para calcular a matriz com as transformações geométricas necessárias para
%executar a planificação ou levantamento do poliedro conforme o valor de P
T=zeros(4,4,N,42);

if P==-1 %executa a planificação
    a=linspace(1,0,N);
else     %executa a desplanificação
    a=linspace(0,1,N);
end

for i=1:42
    for n=1:N
        if i==1
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-0.1*pi)*trans(-x,-y,-z);
        elseif i==2
            T(:,:,n,i)=trans(x,y,z)*rotz(0.1*pi)*trans(ldi,0,0);
        elseif i==3
            T(:,:,n,i)=roty(-a(n)*angc2)*trans(-l-ldi,0,0)*rotz(-0.1*pi)*trans(-x,-y,-z);
        elseif i==4
            T(:,:,n,i)=trans(x,y,z)*rotz(0.1*pi)*trans(ldi+l,0,0);
        elseif i==5
            T(:,:,n,i)=roty(-a(n)*angpent)*trans(-ldi-2*l,0,0)*rotz(-0.1*pi)*trans(-x,-y,-z);
        elseif i==6
            T(:,:,n,i)=trans(x,y,z)*rotz(0.1*pi)*trans(ldi+2*l,0,0);
        elseif i==7
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-0.3*pi)*trans(-x,-y,-z);
        elseif i==8
            T(:,:,n,i)=trans(x,y,z)*rotz(0.3*pi)*trans(ldi,0,0);
        elseif i==9
            T(:,:,n,i)=roty(-a(n)*angtri2)*trans(-l-ldi,0,0)*rotz(-0.3*pi)*trans(-x,-y,-z);
        elseif i==10
            T(:,:,n,i)=trans(x,y,z)*rotz(0.3*pi)*trans(ldi+l,0,0);
        elseif i==11
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-0.5*pi)*trans(-x,-y,-z);
        elseif i==12
            T(:,:,n,i)=trans(x,y,z)*rotz(0.5*pi)*trans(ldi,0,0);
        elseif i==13
            T(:,:,n,i)=roty(-a(n)*angc2)*trans(-l-ldi,0,0)*rotz(-0.5*pi)*trans(-x,-y,-z);
        elseif i==14
            T(:,:,n,i)=trans(x,y,z)*rotz(0.5*pi)*trans(ldi+l,0,0);
        elseif i==15
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-0.7*pi)*trans(-x,-y,-z);
        elseif i==16
            T(:,:,n,i)=trans(x,y,z)*rotz(0.7*pi)*trans(ldi,0,0);
        elseif i==17
            T(:,:,n,i)=roty(-a(n)*angtri2)*trans(-l-ldi,0,0)*rotz(-0.7*pi)*trans(-x,-y,-z);
        elseif i==18
            T(:,:,n,i)=trans(x,y,z)*rotz(0.7*pi)*trans(ldi+l,0,0);
        elseif i==19
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-0.9*pi)*trans(-x,-y,-z);
        elseif i==20
            T(:,:,n,i)=trans(x,y,z)*rotz(0.9*pi)*trans(ldi,0,0);
        elseif i==21
            T(:,:,n,i)=roty(-a(n)*angc2)*trans(-l-ldi,0,0)*rotz(-0.9*pi)*trans(-x,-y,-z);
        elseif i==22
            T(:,:,n,i)=trans(x,y,z)*rotz(0.9*pi)*trans(ldi+l,0,0);
        elseif i==23
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-1.1*pi)*trans(-x,-y,-z);
        elseif i==24
            T(:,:,n,i)=trans(x,y,z)*rotz(1.1*pi)*trans(ldi,0,0);
        elseif i==25 
            T(:,:,n,i)=roty(-a(n)*angtri2)*trans(-l-ldi,0,0)*rotz(-1.1*pi)*trans(-x,-y,-z);
        elseif i==26
            T(:,:,n,i)=trans(x,y,z)*rotz(1.1*pi)*trans(ldi+l,0,0);
        elseif i==27
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-1.3*pi)*trans(-x,-y,-z);
        elseif i==28
            T(:,:,n,i)=trans(x,y,z)*rotz(1.3*pi)*trans(ldi,0,0);
        elseif i==29
            T(:,:,n,i)=roty(-a(n)*angc2)*trans(-l-ldi,0,0)*rotz(-1.3*pi)*trans(-x,-y,-z);
        elseif i==30
            T(:,:,n,i)=trans(x,y,z)*rotz(1.3*pi)*trans(ldi+l,0,0);
        elseif i==31
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-1.5*pi)*trans(-x,-y,-z);
        elseif i==32
            T(:,:,n,i)=trans(x,y,z)*rotz(1.5*pi)*trans(ldi,0,0);
        elseif i==33
            T(:,:,n,i)=roty(-a(n)*angtri2)*trans(-l-ldi,0,0)*rotz(-1.5*pi)*trans(-x,-y,-z);
        elseif i==34
            T(:,:,n,i)=trans(x,y,z)*rotz(1.5*pi)*trans(ldi+l,0,0);
        elseif i==35
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-1.7*pi)*trans(-x,-y,-z);
        elseif i==36
            T(:,:,n,i)=trans(x,y,z)*rotz(1.7*pi)*trans(ldi,0,0);
        elseif i==37
            T(:,:,n,i)=roty(-a(n)*angc2)*trans(-l-ldi,0,0)*rotz(-1.7*pi)*trans(-x,-y,-z);
        elseif i==38
            T(:,:,n,i)=trans(x,y,z)*rotz(1.7*pi)*trans(ldi+l,0,0);
        elseif i==39
            T(:,:,n,i)=roty(-a(n)*(pi/2))*trans(-ldi,0,0)*rotz(-1.9*pi)*trans(-x,-y,-z);
        elseif i==40
            T(:,:,n,i)=trans(x,y,z)*rotz(1.9*pi)*trans(ldi,0,0);
        elseif i==41     
            T(:,:,n,i)=roty(-a(n)*angtri2)*trans(-l-ldi,0,0)*rotz(-1.9*pi)*trans(-x,-y,-z);
        elseif i==42
            T(:,:,n,i)=trans(x,y,z)*rotz(1.9*pi)*trans(ldi+l,0,0);
        end
    end
    
end


