BOXTOPOLYGON Convert a bounding box to a square polygon. poly = boxToPolygon(box) Utility function that convert box data in [XMIN XMAX YMIN YMAX] format to polygon data corresponding to the box boundary. The resulting POLY is a 4-by-2 array. Example box = [ 10 50 20 40]; poly = boxToPolygon(box) poly = 10 20 50 20 50 40 10 40 See also boxes2d, polygons2d, boxToRect
0001 function poly = boxToPolygon(box) 0002 %BOXTOPOLYGON Convert a bounding box to a square polygon. 0003 % 0004 % poly = boxToPolygon(box) 0005 % Utility function that convert box data in [XMIN XMAX YMIN YMAX] format 0006 % to polygon data corresponding to the box boundary. The resulting POLY 0007 % is a 4-by-2 array. 0008 % 0009 % 0010 % Example 0011 % box = [ 10 50 20 40]; 0012 % poly = boxToPolygon(box) 0013 % poly = 0014 % 10 20 0015 % 50 20 0016 % 50 40 0017 % 10 40 0018 % 0019 % See also 0020 % boxes2d, polygons2d, boxToRect 0021 0022 % ------ 0023 % Author: David Legland 0024 % e-mail: david.legland@nantes.inra.fr 0025 % Created: 2017-09-10, using Matlab 8.6.0.267246 (R2015b) 0026 % Copyright 2017 INRA - Cepia Software Platform. 0027 0028 % extreme coordinates 0029 xmin = box(1); 0030 xmax = box(2); 0031 ymin = box(3); 0032 ymax = box(4); 0033 0034 % convert to polygon 0035 poly = [... 0036 xmin ymin; ... 0037 xmax ymin; ... 0038 xmax ymax; ... 0039 xmin ymax];