% a particular nonuniform triangular mesh, to demonstrate the datastructure.
% 29 vertices and 42 triangles

vertices = [ ...
         0    1.0000
    0.3500    1.0000
    0.2276    0.8151
         0    0.7500
    0.7000    1.0000
    0.4730    0.8232
    0.3585    0.6909
    0.1911    0.6261
         0    0.5000
    0.8500    0.8500
    0.6635    0.7934
    0.5377    0.6403
    0.3648    0.5489
    0.2000    0.4500
    1.0000    0.7000
    0.7539    0.6543
    0.5008    0.4848
    0.6446    0.4869
    0.4000    0.4000
    1.0000    0.3500
    0.8191    0.4578
    0.5542    0.3482
    0.6936    0.3385
    0.4500    0.2000
    1.0000         0
    0.8157    0.2207
    0.6279    0.1838
    0.5000         0
    0.7500         0 ];

triangles = [ ...
  2 ,  1 ,  3
  3 ,  1 ,  4
  5 ,  2 ,  6
  2 ,  3 ,  6
  3 ,  4 ,  8
  6 ,  3 ,  7
  3 ,  8 ,  7
  8 ,  4 ,  9
 11 ,  5 ,  6
 10 ,  5 , 11
 12 ,  6 ,  7
 12 , 11 ,  6
 12 ,  7 , 13
  7 ,  8 , 13
  8 , 14 , 13
  8 ,  9 , 14
 16 , 15 , 10
 16 , 10 , 11
 12 , 16 , 11
 18 , 12 , 17
 12 , 13 , 17
 18 , 16 , 12
 17 , 13 , 19
 13 , 14 , 19
 21 , 15 , 16
 21 , 20 , 15
 18 , 21 , 16
 17 , 19 , 22
 17 , 22 , 18
 22 , 23 , 18
 23 , 21 , 18
 19 , 24 , 22
 26 , 25 , 20
 21 , 26 , 20
 23 , 26 , 21
 22 , 24 , 27
 22 , 27 , 23
 23 , 27 , 26
 24 , 28 , 27
 29 , 25 , 26
 27 , 29 , 26
 28 , 29 , 27 ];
 
% plot the mesh
figure(1)
clf
x = vertices(:,1); y = vertices(:,2); z = 0*x;
trisurf(triangles,x,y,z,'facecolor',[.9,.9,1])
view(2)
axis equal
axis off
% label vertices
hold on
for i = 1:length(x)
  t=text(x(i),y(i),sprintf('%2d',i));
  set(t,'fontsize',15,'color',[0,0,.5],'horizontalalign','center','verticalalign','middle')
end
% label triangles
for i = 1:length(triangles)
  t=text(mean(x(triangles(i,:))),mean(y(triangles(i,:))),sprintf('%2d',i));
  set(t,'fontsize',15,'color',[.5,0,0],'horizontalalign','center','verticalalign','middle')
end
