www.pudn.com > calibr8.zip > transform.m
function coords = transform(coords, matrix, offset)
%coords = TRANSFORM(coords, matrix, offset)
%
%Transform points with respect to the transformation matrix and offset
%
%Input:
% COORDS - coordinates of points (array with the last dimension 2 or 3)
% MATRIX - matrix which should be applied
% OFFSET - offset of points (default 0)
%
%Output:
% COORDS - new coordinates of the points
%
%Notes:
% The transformation works for both 2-D and 3-D data.
% If the dimension of MATRIX is 3x3 (or 2x2 for 2-D case), normal matrix
% multiplication is performed. If the dimension is 4x4 (or 3x3 for 2-D case,
% homogeneous coordinates are used for the computation. If OFFSET is given,
% the points are shifted by this offset before the multiplication.
%
%See also:
% ROTMATRIX, DIR2ROT
%
%Radim Halir, Charles University Prague, halir@ms.mff.cuni.cz
%Created: 25.9.1996
%Last modified 14.1.1998
dims = size(coords);
[array, m, n] = data2cols(coords);
if (nargin > 2)
array = mvop(array, offset, '+');
end
homogen = (size(matrix, 1) ~= n);
if (homogen)
array = [array, ones(prod(m), 1)];
end
array = array * matrix.';
if (homogen)
array = mvop(array(:, 1 : n), array(:, n + 1), './');
end
coords = reshape(array, dims);