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
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 % Author: David Legland 0023 % E-mail: david.legland@inrae.fr 0024 % Created: 2004-04-06 0025 % Copyright 2004-2024 INRA - TPV URPOI - BIA IMASTE 0026 0027 if isempty(varargin) 0028 % assert translation with null vector 0029 dx = 0; 0030 dy = 0; 0031 dz = 0; 0032 elseif isscalar(varargin) 0033 % translation vector given in a single argument 0034 var = varargin{1}; 0035 dx = var(1); 0036 dy = var(2); 0037 dz = var(3); 0038 else 0039 % translation vector given in 3 arguments 0040 dx = varargin{1}; 0041 dy = varargin{2}; 0042 dz = varargin{3}; 0043 end 0044 0045 % create the translation matrix 0046 trans = [1 0 0 dx ; 0 1 0 dy ; 0 0 1 dz; 0 0 0 1];