%  ex10.m
%
%  Example 1: graphics of the triangular mesh 
%  without triangle labels
%  without rectangular boxes
%
%  Jiangguo (James) Liu
%  ColoState, Dec. 2005

clear all;
close all;

pderect([-1 1 -1 1]);

disp('Export mesh data, then continue...');
pause;

NumElts = size(t,2);
NumNds = size(p,2);

figure(1);
hold on;

x = zeros(3,1);
y = zeros(3,1);

for j=1:NumElts
   for i=1:3
      x(i) = p(1,t(i,j));
      y(i) = p(2,t(i,j));
   end
   fill(x,y,'w');
end

print -f1 -depsc2 ex10.eps;

%  Write the triangular mesh data to a file
fp = fopen('TrigMesh.dat','wt');
fprintf(fp,'%4d  %4d\n',NumElts, NumNds);
for i=1:NumElts
   fprintf(fp,'%4d  %4d  %4d\n',t(1:3,i));
end
for i=1:NumNds
   fprintf(fp,'%8.4f  %8.4f\n',p(:,i));
end
fclose(fp);

disp('Press any key to close all windows...');
pause;
close all;

return;
