MATLAB: Connecting the 3d faces of a polygon together

3d3d plotsMATLAB

Hi everyone,
I have two faces of a polygon in 3d, meaning that I have drawn the opposite faces of the 3d figure with nothing in between. The values for the x,y, and z coordinates for each face have been stored into x-coor, y-coor, and z-coor arrays for each face respectively.
For instance, face 1 has all x-coors stored in array x, face 2 has x-coors stored in arrayx2, face 1 has y-coors stored in array y, etc.
Any ideas on how to connect the corresponding points from each face together to form a full solid? Thanks.

Best Answer

http://www.mathworks.com/help/matlab/ref/patch.html and scan down to "Specifying Patch Object Shapes" and the second group of code, the one starting with
% The Vertices property contains the coordinates of each
and you can use the method shown there. So in your case, the Vertices would be
verts = [x(:), y(:), z(:); x2(:), y2(:), z2(:)];
and your faces would start
numvert = length(x);
faces(1,:) = 1:numvert; %draw first polygon
faces(2,:) = numvert+1:2*numvert; %draw second polygon
and then
vL = (1 : numvert - 1) .';
faces(2+vL,1:4) = [vL, vL + 1, numvert + 1 + vL, numvert + vL];
faces(2+numvert,1:4) = [numvert, 1, 2*numvert, numvert+1];
This creates a whole bunch of 4-sided polygons, connecting each point to the next point, then over to the corresponding next point, then back to the corresponding point, with an implicit close back to the original point. You did not explicitly ask for such polygons, but if you do not use triangles or quads then you will not get a "solid" like you asked for.
Related Question