Home > matGeom > geom2d > createScaling.m

createScaling

PURPOSE ^

CREATESCALING Create the 3*3 matrix of a scaling in 2 dimensions.

SYNOPSIS ^

function trans = createScaling(varargin)

DESCRIPTION ^

CREATESCALING Create the 3*3 matrix of a scaling in 2 dimensions.

   TRANS = createScaling(SX, SY);
   return the matrix corresponding to scaling by SX and SY in the 2
   main directions.
   The returned matrix has the form:
   [SX  0  0]
   [0  SY  0]
   [0   0  1]

   TRANS = createScaling(SX);
   Assume SX and SY are equals.

   TRANS = createScaling(CENTER, ...);
   Specifies the center of the scaling transform. The argument CENTER
   should be a 1-by-2 array representing coordinates of center.

   See also:
   transforms2d, transformPoint, createTranslation, createRotation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function trans = createScaling(varargin)
0002 %CREATESCALING Create the 3*3 matrix of a scaling in 2 dimensions.
0003 %
0004 %   TRANS = createScaling(SX, SY);
0005 %   return the matrix corresponding to scaling by SX and SY in the 2
0006 %   main directions.
0007 %   The returned matrix has the form:
0008 %   [SX  0  0]
0009 %   [0  SY  0]
0010 %   [0   0  1]
0011 %
0012 %   TRANS = createScaling(SX);
0013 %   Assume SX and SY are equals.
0014 %
0015 %   TRANS = createScaling(CENTER, ...);
0016 %   Specifies the center of the scaling transform. The argument CENTER
0017 %   should be a 1-by-2 array representing coordinates of center.
0018 %
0019 %   See also:
0020 %   transforms2d, transformPoint, createTranslation, createRotation
0021 
0022 %
0023 %   ---------
0024 %   author : David Legland
0025 %   INRA - TPV URPOI - BIA IMASTE
0026 %   created the 07/04/2004.
0027 
0028 
0029 %   HISTORY
0030 %   04/01/2007: rename as scaling
0031 %   22/04/2009: rename as createScaling
0032 
0033 % defined default arguments
0034 sx = 1;
0035 sy = 1;
0036 cx = 0;
0037 cy = 0;
0038 
0039 % process input arguments
0040 if nargin == 1
0041     % the argument is either the scaling factor in both direction,
0042     % or a 1x2 array containing scaling factor in each direction
0043     var = varargin{1};
0044     sx = var(1);
0045     sy = var(1);
0046     if length(var)>1
0047         sy = var(2);
0048     end
0049 elseif nargin == 2
0050     % the 2 arguments are the scaling factors in each dimension
0051     sx = varargin{1};
0052     sy = varargin{2};
0053 elseif nargin == 3
0054     % first argument is center, 2nd and 3d are scaling factors
0055     center = varargin{1};
0056     cx = center(1);
0057     cy = center(2);
0058     sx = varargin{2};
0059     sy = varargin{3};
0060 end
0061 
0062 % concatenate results in a 3-by-3 matrix
0063 trans = [sx 0 cx*(1-sx); 0 sy cy*(1-sy); 0 0 1];
0064

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