Home > matGeom > geom2d > transformVector.m

transformVector

PURPOSE ^

TRANSFORMVECTOR Transform a vector with an affine transform.

SYNOPSIS ^

function varargout = transformVector(varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 % Author: David Legland
0028 % E-mail: david.legland@inrae.fr
0029 % Created: 2007-03-12
0030 % Copyright 2007-2024 INRA - TPV URPOI - BIA IMASTE
0031 
0032 if length(varargin)==2
0033     var = varargin{1};
0034     vx = var(:,1);
0035     vy = var(:,2);
0036     trans = varargin{2};
0037 elseif length(varargin)==3
0038     vx = varargin{1};
0039     vy = varargin{2};
0040     trans = varargin{3};
0041 else
0042     error('wrong number of arguments in "transformVector"');
0043 end
0044 
0045 
0046 % compute new position of vector
0047 vx2 = vx*trans(1,1) + vy*trans(1,2);
0048 vy2 = vx*trans(2,1) + vy*trans(2,2);
0049 
0050 % format output
0051 if nargout==0 || nargout==1
0052     varargout{1} = [vx2 vy2];
0053 elseif nargout==2
0054     varargout{1} = vx2;
0055     varargout{2} = vy2;
0056 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022