function [btotg, detJt, Tra,detra2,BK ]=BmatrixH20(coordor,Ns8,Nt8,Nu8)

b1=zeros(6,60,8);
detJt=zeros(8,1);
BK=zeros(6,60);

% passaggio al sistema di riferimento locale
[coord,Tra,tradef,detra2,traspo]=local_sysH20(coordor);

xn=coord(:,1);
yn=coord(:,2);
zn=coord(:,3);


for ii=1:8
    
    Nxi=Ns8(ii,:);
    Net=Nt8(ii,:);
    Nze=Nu8(ii,:);
    
    xs=Nxi*xn;
    
    xu=Nze*xn;
    
    xt=Net*xn;
    
    ys=Nxi*yn;
    
    yu=Nze*yn;
    
    yt=Net*yn;
    
    zs=Nxi*zn;
    
    zu=Nze*zn;
    
    zt=Net*zn;
    
    
    J=[xs, ys, zs
        xt, yt, zt
        xu, yu, zu];

        detJ=xs*yt*zu+ys*zt*xu+zs*xt*yu-zs*yt*xu-ys*xt*zu-xs*zt*yu;

    % derivate funzioni di forma rispetto a x,y,z
    Nstu=[Nxi;Net;Nze];
    Nxyz=J\Nstu;
    
    Nx=Nxyz(1,:);
    Ny=Nxyz(2,:);
    Nz=Nxyz(3,:);
    
    b1(:,:,ii)=[Nx,zeros(1,40);
        zeros(1,20),Ny,zeros(1,20);
        zeros(1,40),Nz;
        Ny,Nx,zeros(1,20);
        zeros(1,20),Nz,Ny;
        Nz,zeros(1,20),Nx];
    
    detJt(ii,1)=detJ;
    
end

indexdof=zeros(1,60);
for ii=0:19
    indexdof(1,ii*3+1:ii*3+3)=[1+ii,21+ii,41+ii];
end


b1(:,:,:)=b1(:,indexdof,:);

Tr=eye(60);
for ii=1:20
    Tr(ii*3-2:ii*3,ii*3-2:ii*3)=traspo;
end


% applicazione delle trasformazioni di spostamento e coordinate nello spazio
% cartesiano distorto
btotg=zeros(6,60,8);
for ii=1:8
    btotg(:,:,ii)=tradef*b1(:,:,ii)*Tr;
    BK=BK+btotg(:,:,ii)*detJt(ii);
end

end % fucntion end