⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewgrid.m

📁 gridgen是一款强大的网格生成程序
💻 M
字号:
function viewgrid(prm, v)% VIEWGRID Visualises grids generated by `gridgen'.% Usage:%   viewgrid('<gridgen prm file>')       -- display grid only%   viewgrid('<gridgen prm file>', 'v')  -- display grid and image on one%                                           chart, vertically one under another%   viewgrid('<gridgen prm file>', 'h')  -- display grid and image on one%                                           chart, horizontally one aside other%   viewgrid('<gridgen prm file>', '<any other character than 'v' or 'h'>) --%                                           display grid and image on two%                                           different charts%%   For the image display to work, an entry `rectangle' must be%   specified in the `gridgen' parameter file.  if (exist('v','var'))    warning off;    [geom,data,rect] = rfnames(prm);    warning on;    if (~exist('rect','var'))      fprintf('  Warning: the image file not specified in \"%s\"\n', prm);    end  else    [geom,data] = rfnames(prm);  end    f = fopen(geom);  count = 0;  if (f >= 0)    count = 0;    str = fgetl(f);    while (str >= 0)      if (str(1) ~= '#')	count = count + 1;	xy = sscanf(str, '%f %f %f');	xc(count) = xy(1);	yc(count) = xy(2);	if (length(xy) > 2)	  zc(count) = xy(3);	else	  zc(count) = 0;	end      end      str = fgetl(f);    end        xc_pos = xc(zc > 0);    xc_neg = xc(zc < 0);    yc_pos = yc(zc > 0);    yc_neg = yc(zc < 0);        if (xc(count) ~= xc(1) | yc(count) ~= yc(1))      count = count + 1;      xc(count) = xc(1);      yc(count) = yc(1);    end    fclose(f);  end    f = fopen(data);  if (f > 0)    count = 0;    str = fgetl(f);    while (str >= 0)      if (str(1) ~= '#')        count = count + 1;	xy = sscanf(str, '%f %f');	x(count) = xy(1);	y(count) = xy(2);      end      str = fgetl(f);    end    fclose(f);  end  figure1 = figure;  if (exist('rect','var'))    if (exist('v','var') & v == 'v')      subplot(2,1,2);    elseif (exist('v','var') & v == 'h')      subplot(1,2,2);    else      figure2 = figure;    end    r = load(rect);    xr = r(:, 1);    yr = r(:, 2);    n = length(xr);    xr(n + 1) = xr(1);    yr(n + 1) = yr(1);    plot(xr, yr, 'k-', xr, yr, 'k.');    title('Image');    axis equal;    xmin = min(xr);    xmax = max(xr);    ymin = min(yr);    ymax = max(yr);    dx = (xmax - xmin) * 0.05;    dy = (ymax - ymin) * 0.05;    axis([(xmin - dx) (xmax + dx) (ymin - dy) (ymax + dy)]);    grid on;  end  figure(figure1);  if (exist('rect','var'))    if (exist('v','var') & v == 'v')      subplot(2,1,1);    elseif (exist('v','var') & v == 'h')      subplot(1,2,1);    end  end  if (exist('xc','var'))    if (length(xc_neg) > 0)      plot(x, y, '.', xc, yc, 'k-', xc, yc, 'k.', xc_pos, yc_pos, 'go', xc_neg, yc_neg, 'rd');      legend('grid nodes', 'boundary', 'boundary vertices', 'positive turn points', 'negative turn points');    else      plot(x, y, '.', xc, yc, 'k-', xc, yc, 'k.', xc_pos, yc_pos, 'go');      legend('grid nodes', 'boundary', 'boundary vertices', 'turn points');    end  else    plot(x, y, '.');  end  title(strcat('Original polygon and generated nodes ("', data, '")'));  axis equal;  xmin = min(xc);  xmax = max(xc);  ymin = min(yc);  ymax = max(yc);  dx = (xmax - xmin) * 0.05;  dy = (ymax - ymin) * 0.05;  axis([(xmin - dx) (xmax + dx) (ymin - dy) (ymax + dy)]);return;function [geom,data,rect] = rfnames(prm);  f = fopen(prm);  if (f < 0)    return;  end    seps = char([32,92]);  str = fgetl(f);  while (str >= 0)    if (str(1) ~= '#')      [first,str] = strtok(str, seps);      if (strcmpi(first, 'input'))	geom = strtok(str, seps);      elseif (strcmpi(first, 'output'))	data = strtok(str, seps);      elseif (strcmpi(first, 'rectangle'))	rect = strtok(str, seps);      end    end    str = fgetl(f);  end    fclose(f);  return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -