Home > matGeom > geom2d > drawBox.m

drawBox

PURPOSE ^

DRAWBOX Draw a box defined by coordinate extents.

SYNOPSIS ^

function varargout = drawBox(box, varargin)

DESCRIPTION ^

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 = pointSetBounds(points);
     figure; hold on;
     drawPoint(points, 's');
     drawBox(box);
     axis([0 60 0 60]);

   See Also:
   drawOrientedBox, drawRect

   ---------
   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 10/12/2003.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 = pointSetBounds(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 %   author : David Legland
0028 %   INRA - TPV URPOI - BIA IMASTE
0029 %   created the 10/12/2003.
0030 %
0031 
0032 %   HISTORY
0033 %   2010-02-22 creation
0034 %   2011-04-01 add support for drawing option, fix bug for several boxes
0035 %   2011-10-11 add management of axes handle
0036 
0037 % extract handle of axis to draw on
0038 if isAxisHandle(box)
0039     ax = box;
0040     box = varargin{1};
0041     varargin(1) = [];
0042 else
0043     ax = gca;
0044 end
0045 
0046 % default values
0047 xmin = box(:,1);
0048 xmax = box(:,2);
0049 ymin = box(:,3);
0050 ymax = box(:,4);
0051 
0052 nBoxes = size(box, 1);
0053 r = zeros(nBoxes, 1);
0054 
0055 % iterate on boxes
0056 for i = 1:nBoxes
0057     % exract min and max values
0058     tx(1) = xmin(i);
0059     ty(1) = ymin(i);
0060     tx(2) = xmax(i);
0061     ty(2) = ymin(i);
0062     tx(3) = xmax(i);
0063     ty(3) = ymax(i);
0064     tx(4) = xmin(i);
0065     ty(4) = ymax(i);
0066     tx(5) = xmin(i);
0067     ty(5) = ymin(i);
0068 
0069     % display polygon
0070     r(i) = plot(ax, tx, ty, varargin{:});
0071 end
0072 
0073 % format output
0074 if nargout > 0
0075     varargout = {r};
0076 end

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