| 1 |
function plot_mesh2(mesh, varargin) |
| 2 |
% |
| 3 |
% plot_mesh2(mesh, option) |
| 4 |
% |
| 5 |
% plot the mesh |
| 6 |
% |
| 7 |
% Input: |
| 8 |
% mesh structure array with the following fields |
| 9 |
% |
| 10 |
% mesh.p Real np x 2 |
| 11 |
% array containing the x- and y- coordinates |
| 12 |
% of the nodes |
| 13 |
% |
| 14 |
% mesh.t Integer nt x nn |
| 15 |
% t(i,1:nn) contains the indices of the vertices of |
| 16 |
% cell i. |
| 17 |
% |
| 18 |
% option option = [i,j] controls the labels of the plot: |
| 19 |
% i = 0 no cell numbers |
| 20 |
% i = 1 print cell numbers |
| 21 |
% j = 0 no node numbers |
| 22 |
% j = 1 print node numbers |
| 23 |
% If GridPlot is called without option, then no labels are plotted |
| 24 |
% |
| 25 |
% AUTHOR: Matthias Heinkenschloss and Denis Ridzal |
| 26 |
% Department of Computational and Applied Mathematics |
| 27 |
% Rice University |
| 28 |
% November 23, 2005 |
| 29 |
|
| 30 |
|
| 31 |
% get number of cells, nt, and |
| 32 |
% number of nodes per cell, nn. |
| 33 |
[nt,nn] = size(mesh.t) |
| 34 |
|
| 35 |
if( nargin == 1 ) |
| 36 |
nodelabel = 0; |
| 37 |
trianglabel = 0; |
| 38 |
else |
| 39 |
nodelabel = varargin{1}(2); |
| 40 |
trianglabel = varargin{1}(1); |
| 41 |
end |
| 42 |
|
| 43 |
% Plot grid. |
| 44 |
xx = zeros(1,4); |
| 45 |
yy = zeros(1,4); |
| 46 |
for it = 1:nt |
| 47 |
xx = mesh.p(mesh.t(it,1:nn),1); |
| 48 |
yy = mesh.p(mesh.t(it,1:nn),2); |
| 49 |
xx(nn+1) = mesh.p(mesh.t(it,1),1); |
| 50 |
yy(nn+1) = mesh.p(mesh.t(it,1),2); |
| 51 |
plot(xx,yy,'r'); hold on |
| 52 |
end |
| 53 |
axis( [min(mesh.p(:,1)) max(mesh.p(:,1)) min(mesh.p(:,2)) max(mesh.p(:,2))] ); |
| 54 |
|
| 55 |
|
| 56 |
if( nodelabel == 1 ) |
| 57 |
% Label nodes (in green) |
| 58 |
for i = 1:nt |
| 59 |
plot(mesh.p(mesh.t(i,(1:nn)),1),... |
| 60 |
mesh.p(mesh.t(i,(1:nn)),2),'go') |
| 61 |
for j = 1:nn |
| 62 |
x = mesh.p(mesh.t(i,j),1); |
| 63 |
y = mesh.p(mesh.t(i,j),2); |
| 64 |
h = text(x,y,int2str(mesh.t(i,j))); |
| 65 |
set(h,'Color','k','FontSize',11,'FontWeight','bold'); |
| 66 |
end |
| 67 |
end |
| 68 |
end |
| 69 |
|
| 70 |
if( trianglabel == 1 ) |
| 71 |
% Label cells (in blue) |
| 72 |
for i = 1:nt |
| 73 |
x = sum(mesh.p(mesh.t(i,1:nn),1)) / nn; |
| 74 |
y = sum(mesh.p(mesh.t(i,1:nn),2)) / nn; |
| 75 |
h = text(x,y,int2str(i)); |
| 76 |
set(h,'Color','b','FontSize',11); |
| 77 |
end |
| 78 |
end |
| 79 |
hold off |
| 80 |
|
| 81 |
drawnow |