TRANSFORMVECTOR Transform a vector with an affine transform. VECT2 = transformVector(VECT1, TRANS); where VECT1 has the form [xv yv], and TRANS is a [2*2], [2*3] or [3*3] matrix, returns the vector transformed with affine transform TRANS. Format of TRANS can be one of : [a b] , [a b c] , or [a b c] [d e] [d e f] [d e f] [0 0 1] VECT2 = transformVector(VECT1, TRANS); Also works when PTA is a [N*2] array of double. In this case, VECT2 has the same size as VECT1. [vx2 vy2] = transformVector(vx1, vy1, TRANS); Also works when vx1 and vy1 are arrays the same size. The function transform each couple of (vx1, vy1), and return the result in (vx2, vy2), which is the same size as (vx1 vy1). See also: vectors2d, transforms2d, rotateVector, transformPoint --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 12/03/2007.
0001 function varargout = transformVector(varargin) 0002 %TRANSFORMVECTOR Transform a vector with an affine transform. 0003 % 0004 % VECT2 = transformVector(VECT1, TRANS); 0005 % where VECT1 has the form [xv yv], and TRANS is a [2*2], [2*3] or [3*3] 0006 % matrix, returns the vector transformed with affine transform TRANS. 0007 % 0008 % Format of TRANS can be one of : 0009 % [a b] , [a b c] , or [a b c] 0010 % [d e] [d e f] [d e f] 0011 % [0 0 1] 0012 % 0013 % VECT2 = transformVector(VECT1, TRANS); 0014 % Also works when PTA is a [N*2] array of double. In this case, VECT2 has 0015 % the same size as VECT1. 0016 % 0017 % [vx2 vy2] = transformVector(vx1, vy1, TRANS); 0018 % Also works when vx1 and vy1 are arrays the same size. The function 0019 % transform each couple of (vx1, vy1), and return the result in 0020 % (vx2, vy2), which is the same size as (vx1 vy1). 0021 % 0022 % 0023 % See also: 0024 % vectors2d, transforms2d, rotateVector, transformPoint 0025 % 0026 % --------- 0027 % 0028 % author : David Legland 0029 % INRA - TPV URPOI - BIA IMASTE 0030 % created the 12/03/2007. 0031 % 0032 0033 % HISTORY 0034 0035 0036 if length(varargin)==2 0037 var = varargin{1}; 0038 vx = var(:,1); 0039 vy = var(:,2); 0040 trans = varargin{2}; 0041 elseif length(varargin)==3 0042 vx = varargin{1}; 0043 vy = varargin{2}; 0044 trans = varargin{3}; 0045 else 0046 error('wrong number of arguments in "transformVector"'); 0047 end 0048 0049 0050 % compute new position of vector 0051 vx2 = vx*trans(1,1) + vy*trans(1,2); 0052 vy2 = vx*trans(2,1) + vy*trans(2,2); 0053 0054 % format output 0055 if nargout==0 || nargout==1 0056 varargout{1} = [vx2 vy2]; 0057 elseif nargout==2 0058 varargout{1} = vx2; 0059 varargout{2} = vy2; 0060 end