DRAWBOX Draw a box defined by coordinate extents. drawBox(BOX) Draws a box defined by its extent: BOX = [XMIN XMAX YMIN YMAX]. drawBox(..., NAME, VALUE) Specifies drawing parameters using parameter name and value. See plot function for syntax. drawBox(AX, ...) Specifies the handle of the axis to draw on. Example % define some points, compute their box, display everything points = [10 30; 20 50; 20 20; 30 10;40 30;50 20]; box = boundingBox(points); figure; hold on; drawPoint(points, 's'); drawBox(box); axis([0 60 0 60]); See also drawOrientedBox, drawRect
0001 function varargout = drawBox(box, varargin) 0002 %DRAWBOX Draw a box defined by coordinate extents. 0003 % 0004 % drawBox(BOX) 0005 % Draws a box defined by its extent: BOX = [XMIN XMAX YMIN YMAX]. 0006 % 0007 % drawBox(..., NAME, VALUE) 0008 % Specifies drawing parameters using parameter name and value. See plot 0009 % function for syntax. 0010 % 0011 % drawBox(AX, ...) 0012 % Specifies the handle of the axis to draw on. 0013 % 0014 % Example 0015 % % define some points, compute their box, display everything 0016 % points = [10 30; 20 50; 20 20; 30 10;40 30;50 20]; 0017 % box = boundingBox(points); 0018 % figure; hold on; 0019 % drawPoint(points, 's'); 0020 % drawBox(box); 0021 % axis([0 60 0 60]); 0022 % 0023 % See also 0024 % drawOrientedBox, drawRect 0025 % 0026 0027 % ------ 0028 % Author: David Legland 0029 % E-mail: david.legland@inrae.fr 0030 % Created: 2003-12-10 0031 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE 0032 0033 % extract handle of axis to draw on 0034 if isAxisHandle(box) 0035 ax = box; 0036 box = varargin{1}; 0037 varargin(1) = []; 0038 else 0039 ax = gca; 0040 end 0041 0042 % default values 0043 xmin = box(:,1); 0044 xmax = box(:,2); 0045 ymin = box(:,3); 0046 ymax = box(:,4); 0047 0048 nBoxes = size(box, 1); 0049 r = zeros(nBoxes, 1); 0050 0051 % iterate on boxes 0052 for i = 1:nBoxes 0053 % exract min and max values 0054 tx(1) = xmin(i); 0055 ty(1) = ymin(i); 0056 tx(2) = xmax(i); 0057 ty(2) = ymin(i); 0058 tx(3) = xmax(i); 0059 ty(3) = ymax(i); 0060 tx(4) = xmin(i); 0061 ty(4) = ymax(i); 0062 tx(5) = xmin(i); 0063 ty(5) = ymin(i); 0064 0065 % display polygon 0066 r(i) = plot(ax, tx, ty, varargin{:}); 0067 end 0068 0069 % format output 0070 if nargout > 0 0071 varargout = {r}; 0072 end