Home > matGeom > geom2d > drawVector.m

drawVector

PURPOSE ^

DRAWVECTOR Draw vector at a given position.

SYNOPSIS ^

function varargout = drawVector(pos, vect, varargin)

DESCRIPTION ^

DRAWVECTOR Draw vector at a given position.

   drawVector(POS, VECT)
   POS should be a N-by-2 or N-by-3 array containing position of vector
   origins, and VECT should be a N-by-2 or N-by-3 array containing the
   direction of the vectors.

   Example
     figure; hold on;
     drawVector([1 2], [3 2]);
     drawVector([1 2], [-2 3]);
     axis equal;

   See also
     quiver, drawVector3d

 ------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 Created: 2013-03-18,    using Matlab 7.9.0.529 (R2009b)
 Copyright 2013 INRA - Cepia Software Platform.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawVector(pos, vect, varargin)
0002 %DRAWVECTOR Draw vector at a given position.
0003 %
0004 %   drawVector(POS, VECT)
0005 %   POS should be a N-by-2 or N-by-3 array containing position of vector
0006 %   origins, and VECT should be a N-by-2 or N-by-3 array containing the
0007 %   direction of the vectors.
0008 %
0009 %   Example
0010 %     figure; hold on;
0011 %     drawVector([1 2], [3 2]);
0012 %     drawVector([1 2], [-2 3]);
0013 %     axis equal;
0014 %
0015 %   See also
0016 %     quiver, drawVector3d
0017 %
0018 % ------
0019 % Author: David Legland
0020 % e-mail: david.legland@grignon.inra.fr
0021 % Created: 2013-03-18,    using Matlab 7.9.0.529 (R2009b)
0022 % Copyright 2013 INRA - Cepia Software Platform.
0023 
0024 % check input dimension
0025 nd = size(pos, 2);
0026 if size(vect, 2) ~= nd
0027     error('input vector and position must have same dimension');
0028 end
0029 
0030 if nd == 2
0031     % Display 2D vectors
0032     h = quiver(pos(:, 1), pos(:, 2), vect(:, 1), vect(:, 2), 0, varargin{:});
0033     
0034 elseif nd == 3
0035     % Display 3D vectors
0036     h = quiver3(pos(:, 1), pos(:, 2), pos(:, 3), ...
0037         vect(:, 1), vect(:, 2), vect(:, 3), 0, varargin{:});
0038     
0039 else
0040     error('Can not display vectors of dimension > 3');
0041 end
0042 
0043 % format output
0044 if nargout > 0
0045     varargout{1} = h;
0046 end

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