CREATETRANSLATION3D Create the 4x4 matrix of a 3D translation. usage: TRANS = createTranslation3d(DX, DY, DZ); return the translation corresponding to DX and DY. The returned matrix has the form : [1 0 0 DX] [0 1 0 DY] [0 0 1 DZ] [0 0 0 1] TRANS = createTranslation3d(VECT); return the translation corresponding to the given vector [x y z]. See also: transforms3d, transformPoint3d, transformVector3d, createRotationOx, createRotationOy, createRotationOz, createScaling3d --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 06/04/2004.
0001 function trans = createTranslation3d(varargin) 0002 %CREATETRANSLATION3D Create the 4x4 matrix of a 3D translation. 0003 % 0004 % usage: 0005 % TRANS = createTranslation3d(DX, DY, DZ); 0006 % return the translation corresponding to DX and DY. 0007 % The returned matrix has the form : 0008 % [1 0 0 DX] 0009 % [0 1 0 DY] 0010 % [0 0 1 DZ] 0011 % [0 0 0 1] 0012 % 0013 % TRANS = createTranslation3d(VECT); 0014 % return the translation corresponding to the given vector [x y z]. 0015 % 0016 % 0017 % See also: 0018 % transforms3d, transformPoint3d, transformVector3d, 0019 % createRotationOx, createRotationOy, createRotationOz, createScaling3d 0020 % 0021 % --------- 0022 % 0023 % author : David Legland 0024 % INRA - TPV URPOI - BIA IMASTE 0025 % created the 06/04/2004. 0026 % 0027 0028 % HISTORY 0029 % 22/04/2009 rename as createTranslation3d 0030 0031 0032 if isempty(varargin) 0033 % assert translation with null vector 0034 dx = 0; 0035 dy = 0; 0036 dz = 0; 0037 elseif length(varargin)==1 0038 % translation vector given in a single argument 0039 var = varargin{1}; 0040 dx = var(1); 0041 dy = var(2); 0042 dz = var(3); 0043 else 0044 % translation vector given in 3 arguments 0045 dx = varargin{1}; 0046 dy = varargin{2}; 0047 dz = varargin{3}; 0048 end 0049 0050 % create the translation matrix 0051 trans = [1 0 0 dx ; 0 1 0 dy ; 0 0 1 dz; 0 0 0 1];