1 function p = plot_polygon_grid(grid,params)
2 %
function p = plot_polygon_grid(grid[, params])
3 % plot method
for a 2D polygonal grid. This routine can be used
for triangular
4 % and rectangular grids.
6 % A line plot is performed as
default.
9 % params: optional structure holding fields controlling the plot output.
12 % p: This is the list of handles to the graphics primitives
14 % @todo For large grids, the routine can be slow. In these cases interestingly, the
15 % grid plotting should be implemented with patches, as that seems to be
18 % optional fields of params:
19 % color : RGB vector of line/patch color
20 % shrink_factor :
if this flag is given, the elements are plotted shrinked
21 % plot_patch :
if this flag is set the plot is done
23 % axis_equal :
if this flag is set, set axis to equal scale
26 % Bernard Haasdonk 9.5.2007
32 if ~(isfield(params,
'shrink_factor'))
33 params.shrink_factor = 1.0;
36 if ~(isfield(params,
'plot_patch'))
37 params.plot_patch = 0;
40 if ~(isfield(params,
'axis_equal'))
41 params.axis_equal = 0;
44 if ~(isfield(params,
'axis_tight'))
45 params.axis_tight = 0;
48 if ~(isfield(params,
'color'))
49 params.color = [0,0,1];
55 % compute vertex coordinates and scale
56 XX = grid.X(grid.VI(:));
57 XX = reshape(XX,size(grid.VI)); % nelements*4 matrix
58 YY = grid.Y(grid.VI(:));
59 YY = reshape(YY,size(grid.VI)); % nelements*4 matrix
61 CXX = repmat(grid.CX(:),1,nneigh);
62 CYY = repmat(grid.CY(:),1,nneigh);
65 XX = (XX - CXX) *params.shrink_factor + CXX;
66 YY = (YY - CYY) *params.shrink_factor + CYY;
69 p = patch(XX
',YY',params.color);
71 li = [ 1:nneigh; 1:nneigh];
73 li = [li(2:end);li(1)]; % => li = [1 2 2 3 3 4 4 1];
75 XX = XX(:,li)
'; % => 2nneigh X nelements matrix
76 XX = reshape(XX,2,nneigh*grid.nelements);
78 YY = reshape(YY,2,nneigh*grid.nelements);
79 p = line(XX,YY,
'Color',params.color);
87 % DO NOT USE axis tight here!!! takes 1 minute with R2009a !!!!!!!
93 set(gca,
'Xlim',[xmin,xmax],
'Ylim',[ymin, ymax]);