Home > matGeom > polygons2d > writePolygonSet.m

writePolygonSet

PURPOSE ^

WRITEPOLYGONSET Write a set of simple polygons into a file.

SYNOPSIS ^

function writePolygonSet(polys, filename)

DESCRIPTION ^

WRITEPOLYGONSET Write a set of simple polygons into a file.
   
   writePolygonSet(POLYS, FILENAME);
   Writes the set of polygons in the file FILENAME.
   Following format is used:
     X11 X12 X13 ... X1N
     Y11 Y12 Y13 ... Y1N
     X21 X22 X23 ... X2N
     Y21 Y22 Y23 ... Y2N
   Each polygon may have a different number of vertices. 

   See also:
   polygons2d, readPolygonSet

   ---------
   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 14/01/2013.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function writePolygonSet(polys, filename)
0002 %WRITEPOLYGONSET Write a set of simple polygons into a file.
0003 %
0004 %   writePolygonSet(POLYS, FILENAME);
0005 %   Writes the set of polygons in the file FILENAME.
0006 %   Following format is used:
0007 %     X11 X12 X13 ... X1N
0008 %     Y11 Y12 Y13 ... Y1N
0009 %     X21 X22 X23 ... X2N
0010 %     Y21 Y22 Y23 ... Y2N
0011 %   Each polygon may have a different number of vertices.
0012 %
0013 %   See also:
0014 %   polygons2d, readPolygonSet
0015 %
0016 %   ---------
0017 %   author : David Legland
0018 %   INRA - TPV URPOI - BIA IMASTE
0019 %   created the 14/01/2013.
0020 %
0021 
0022 
0023 % open file for reading
0024 fid = fopen(filename, 'wt');
0025 
0026 for i = 1:length(polys)
0027     poly = polys{i};
0028     n = size(poly, 1);
0029     
0030     % precompute format
0031     format = [repmat('%g ', 1, n) '\n'];
0032     
0033     % write one line for x, then one line for y
0034     fprintf(fid, format, poly(:,1)');
0035     fprintf(fid, format, poly(:,2)');    
0036 end
0037 
0038 % close file
0039 fclose(fid);

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019