POLYGONTOROW Convert polygon coordinates to a row vector. ROW = polygonToRow(POLY); where POLY is a N-by-2 array of points representing vertices of the polygon, converts the vertex coordinates into a linear array: ROW = [X1 Y1 X2 Y2 .... XN YN] ROW = polygonToRow(POLY, TYPE); Can coose another format for converting polygon. Possibilities are: 'interlaced' (default}, as described above 'packed': ROW has format [X1 X2 ... XN Y1 Y2 ... YN]. Example square = [10 10 ; 20 10 ; 20 20 ; 10 20]; row = polygonToRow(square) row = 10 10 20 10 20 20 10 20 % the same with different ordering row = polygonToRow(square, 'packed') row = 10 20 20 10 10 10 20 20 See also polygons2d, rowToPolygon ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2010-07-23, using Matlab 7.9.0.529 (R2009b) Copyright 2010 INRA - Cepia Software Platform.
0001 function row = polygonToRow(polygon, varargin) 0002 %POLYGONTOROW Convert polygon coordinates to a row vector. 0003 % 0004 % ROW = polygonToRow(POLY); 0005 % where POLY is a N-by-2 array of points representing vertices of the 0006 % polygon, converts the vertex coordinates into a linear array: 0007 % ROW = [X1 Y1 X2 Y2 .... XN YN] 0008 % 0009 % ROW = polygonToRow(POLY, TYPE); 0010 % Can coose another format for converting polygon. Possibilities are: 0011 % 'interlaced' (default}, as described above 0012 % 'packed': ROW has format [X1 X2 ... XN Y1 Y2 ... YN]. 0013 % 0014 % Example 0015 % square = [10 10 ; 20 10 ; 20 20 ; 10 20]; 0016 % row = polygonToRow(square) 0017 % row = 0018 % 10 10 20 10 20 20 10 20 0019 % 0020 % % the same with different ordering 0021 % row = polygonToRow(square, 'packed') 0022 % row = 0023 % 10 20 20 10 10 10 20 20 0024 % 0025 % 0026 % See also 0027 % polygons2d, rowToPolygon 0028 % 0029 % 0030 % ------ 0031 % Author: David Legland 0032 % e-mail: david.legland@grignon.inra.fr 0033 % Created: 2010-07-23, using Matlab 7.9.0.529 (R2009b) 0034 % Copyright 2010 INRA - Cepia Software Platform. 0035 0036 % determines ordering type 0037 type = 'interlaced'; 0038 if ~isempty(varargin) 0039 type = varargin{1}; 0040 end 0041 0042 0043 if strcmp(type, 'interlaced') 0044 % ordering is [X1 Y1 X2 X2... XN YN] 0045 Np = size(polygon, 1); 0046 row = reshape(polygon', [1 2*Np]); 0047 0048 elseif strcmp(type, 'packed') 0049 % ordering is [X1 X2 X3... XN Y1 Y2 Y3... YN] 0050 row = polygon(:)'; 0051 end