function plotgrid_L1tri(x,e,legend)

% plotgrid_L1tri(x,e,legend)
%            displays a triangulation.

ne = size(e,2);

figure
hold on
for i=1:ne
    ei = e(:,i);

    xi1 = x(:,ei(1));
    xi2 = x(:,ei(2));
    xi3 = x(:,ei(3));
       
    plot([xi1(1),xi2(1)],[xi1(2),xi2(2)]);
    plot([xi2(1),xi3(1)],[xi2(2),xi3(2)]);
    plot([xi3(1),xi1(1)],[xi3(2),xi1(2)]);

    if (legend==1)
        text(xi1(1),xi1(2),int2str(ei(1)));
        text(xi2(1),xi2(2),int2str(ei(2)));
        text(xi3(1),xi3(2),int2str(ei(3)));
        
        t = text((1/3)*(xi1(1)+xi2(1)+xi3(1)),(1/3)*(xi1(2)+xi2(2)+xi3(2)),int2str(i));
        set(t,'Color',[1 0 0]);
    end
end
hold off
