%eg:  histo=disttest('Models/TIRAREX_.3DS',1);

function histo=disttest(filename,show)

if exist('show')==0
    show = 0;
end


%load
if show==1
    subplot(1,3,1);
    axis equal;
end
[vcell,tcell]=read3ds(filename,1,show);
if (length(vcell)==0)
    close;
    return;
end

%surface
p=randomsurfacedistribution(vcell{1},tcell{1},2000);

if show==1
    subplot(1,3,2);
    plot3(p(:,1),p(:,2),p(:,3),'.');
    axis equal;
end

%distance
%cx=sum(p(:,1))/length(p);
%cy=sum(p(:,2))/length(p);
%cz=sum(p(:,3))/length(p);
%cen=[cx cy cz];  %center

dn=20000;
dist=zeros(dn,1);
for i=1:dn
    p1=p(floor(rand(1)*length(p))+1,:);
    p2=p(floor(rand(1)*length(p))+1,:);
    dist(i)=norm(p1-p2);
end

%histogram
sc=50;
dist=sort(dist);
dist=floor(dist / dist(length(dist)) *sc +0.5);
histo=zeros(sc+1,1);
for i=1:length(dist)
    histo(dist(i)+1)=histo(dist(i)+1)+1;
end
for i=2:length(histo)-1
    histo(i)=(histo(i-1)+2*histo(i)+histo(i+1))/4;  %smooth
end


histo=histo/sum(histo);


if show==1
    subplot(1,3,3);
    plot(histo);
end
