原帖由 kangtj 于 2007-11-11 19:32 发表
能把你写的程序帖出来供大家学习吗?!
clear;
[filename,pathname] = uigetfile('*.xyz','Select a file for read...');
InitialData = load(strcat(pathname,filename));
X=InitialData(:,1);
Y=InitialData(:,2);
Z=InitialData(:,3);
minX=min(X);
maxX=max(X);
minY=min(Y);
maxY=max(Y);
step=1;%设置单元格大小
Xi=minX:step:maxX;
Yi=minY:step:maxY;
[X2,Y2]=meshgrid(Xi,Yi);
Z2=griddata(X,Y,Z,X2,Y2,'cubic');
[m,n]=size(Z2);
top_bottom = ones(1,n)*NaN;
left_right = ones(1,m+2)'*NaN;
Z2 =[top_bottom;Z2;top_bottom];
Z2 =[left_right,Z2,left_right];
volume = 0;
for i =2:m+1
for j=2:n+1
if ~isnan(Z2(i,j))%为中间的每个点分配权
counter = 0;
if ~isnan(Z2(i-1,j-1))
counter = counter+1;
end
if ~isnan(Z2(i-1,j))
counter = counter+1;
end
if ~isnan(Z2(i-1,j+1))
counter =counter+1;
end
if ~isnan(Z2(i,j-1))
counter =counter+1;
end
if ~isnan(Z2(i,j+1))
counter =counter+1;
end
if ~isnan(Z2(i+1,j-1))
counter =counter+1;
end
if ~isnan(Z2(i+1,j))
counter =counter+1;
end
if ~isnan(Z2(i+1,j+1))
counter =counter+1;
end
cell_volume = counter/8*Z2(i,j)*step^2;
volume = cell_volume+volume;
end
end
end
以上计算的都很基础,现在我想设定计算的范围又不知道怎么弄了。只能知道多边形定点的坐标,怎么判断点是否在多边形范围内呢?
[ 本帖最后由 spano 于 2007-11-12 14:38 编辑 ] |