function plotquad(qtri,values)

% Example: qtri=[1 3 1 2 2 1;1 1 3 1 2 2];
%          values=[1 0 0 0 0 0];
%          plotquad(qtri,values)
%
xi=qtri(1,:);yi=qtri(1,:);ai=values;

%xi(2,1:6)=[11 13 11 12 12 11]
%yi(2,1:6)=[1 1 3 0 2 2]
%ai(2,1:6)=[4 1 1 1 1 1]

div=40;
step=1/div;

u=0:step:1;
v=0:step:1;
[u,v]=meshgrid(u,v);

lan1=1-u-v;
lan2=u;
lan3=v;



N1=lan1.*(lan1*2-1);
N2=lan2.*(lan2*2-1);
N3=lan3.*(lan3*2-1);

N4=4*lan1.*lan2;
N5=4*lan2.*lan3;
N6=4*lan3.*lan1;

clf
xmin=min(min(xi));
ymin=min(min(yi));
zmin=min(min(ai));
xmax=max(max(xi));
ymax=max(max(yi));
zmax=max(max(ai));

%axis([xmin,xmax,ymin,ymax,zmin,zmax])
%hold on

amax=max(max(ai))*2
if amax==0
amax=min(min(ai))*2
end

for re=1:size(xi,1),
re
x=xi(re,1)*N1+xi(re,2)*N2+xi(re,3)*N3+xi(re,4)*N4+xi(re,5)*N5+xi(re,6)*N6;
y=yi(re,1)*N1+yi(re,2)*N2+yi(re,3)*N3+yi(re,4)*N4+yi(re,5)*N5+yi(re,6)*N6;
a=ai(re,1)*N1+ai(re,2)*N2+ai(re,3)*N3+ai(re,4)*N4+ai(re,5)*N5+ai(re,6)*N6;

%N1=lan1;N2=lan2;N3=lan3;

clear h1;
clear h2;
clear h3;
clear h4;
cnt=1;

 for rx=1:div+1,
  h1(cnt)=x(rx,1);
  h2(cnt)=y(rx,1);
  h3(cnt)=a(rx,1);
  h4(cnt)=a(rx,1)/amax;
  cnt=cnt+1;
 end


 for rxy=div:-1:2,
  h1(cnt)=x(rxy,div-rxy+2);
  h2(cnt)=y(rxy,div-rxy+2);
  h3(cnt)=a(rxy,div-rxy+2);
  h4(cnt)=a(rxy,div-rxy+2)/amax;
  cnt=cnt+1;
 end
 for ry=div+1:-1:2,
  h1(cnt)=x(1,ry);
  h2(cnt)=y(1,ry);
  h3(cnt)=a(1,ry);
  h4(cnt)=a(1,ry)/amax;
  cnt=cnt+1;
 end
h1=h1';
h2=h2';
h3=h3';
h4=h4';
fill3(h1,h2,h3,h4);
hold on;
end

%end


