|
Hello Vincent,
It's not elegant, and I do not have time to look up formats for fill3,
but try (from my book Foundations of Engineering with MATLAB 7):
function main
%P is perimeter given in y-z (x=0) plane
% following routine and subfunctions extrudes in x direction
%Second argument of "extrude" is nx,and gives
% x-resolution=linspace(0,1,nx)
P=[0 0;1 0; 0 1]; %boundary triangle
fv=extrude(P,11); %resolution of 11 in the direction of extrusion
patch(fv, 'FaceVertexCData', ones(length(fv.vertices),1)*[1 .5 .5],...
'FaceColor', 'interp');
axis off; axis equal
fv.vertices %just to let you see vertex values
function fv = extrude(P, nx)
% P is a column vector sequence of
% points for boundary ( [z,y]
% nx is resolution in x direction
% x == linspace(0,1,nx)
nP=length(P)+1;
fv = mesh_triangle(linspace(0,1,nx), ...
linspace(0,1,nP ),...
@(x,y) 0 );
z= reshape(ones(nx,1)*(P(:,1)'), [nx*(nP-1),1]);
z= [z;ones(nx,1)*z(1)];
y= reshape(ones(nx,1)*(P(:,2)'), [nx*(nP-1),1]);
y= [y;ones(nx,1)*y(1)];
fv.vertices = [fv.vertices(:,1) z y];
fv=vertex_match(fv);
function fv2 = vertex_match(fv2)
% % finds repeated vertices and combines them
% % input fv2 is a face vertex structure
% % output fv2 with faces and vertices updated
% % Getting rid of redundant vertices can enhance transformation performance
[fv2.vertices, m, n]=unique(fv2.vertices, 'rows');
fv2.faces=n(fv2.faces);
function fv = mesh_triangle(x, y, f)
%function to generate a data set for use with
% the patch command on a regular grid
% INPUT: x, y 1-D vectors partioning horizontal
% and vertical grids, respectively
% f is function of f(x,y)
% pass @(x,y) 0 for just a grid
% OUTPUT: fv a face-vertex structure
n = length(x); m=length(y);
kount = -1;
fv.faces((m-1)*(n-1)*2,:)=[0 0 0];
fv.vertices(m*n,:)=[0 0 0];
ind = 0;
for jy = 1:m
for ix=1:n
ind = ind+1;
fv.vertices(ind,:)=[x(ix) y(jy) f(x(ix), y(jy))];
end
end
for jy = 1:m-1
for ix = 1:n-1
kount=kount+2;
ind = (jy-1)*n+ix;
fv.faces(kount,:)=[ind ind+1 ind+n+1];
fv.faces(kount+1,:)=[ind ind+n+1 ind+n];
end
end
|