function result = scaleIt(sx,sy) % scaleIt return matrix for scaling of 2D graphics % % consumes: % sx: a scalar, amount to scale by in the x direction % sy: a scalar, amount to scale by in the y direction % % produces: % a 3x3 matrix as follows: % % sx 0 0 % 0 sy 0 % 0 0 1 % % This is the affine tranformation matrix that scales by sx and sy % % Example: % >> scaleIt(3,4) % ans = % % 3 0 0 % 0 4 0 % 0 0 1 % % The following example shows how to use this with a set of (x,y) % coordinates in a 2D space. The extra 1 on each row is just used % to make the math work out---it is not part of the coordinates. % The actual x,y coordinates are (0,0), (2,8), and (4,0), % representing an inverted V shape. Here, we transform by scaling % in the x direction by a factor of 3, and in the y direction by a % factor of 4. % % >> points = [ 0 0 1; 2 8 1; 4 0 1]' % % points = % % 0 2 4 % 0 8 0 % 1 1 1 % % >> % >> newPoints = (scaleIt(3,4) * points) % % newPoints = % 0 6 12 % 0 32 0 % 1 1 1 % >> % result = [ sx 0 0; 0 sy 0; 0 0 1]; return; end