1## Copyright (C) 2021 David Legland 2## All rights reserved. 3## 4## Redistribution and use in source and binary forms, with or without 5## modification, are permitted provided that the following conditions are met: 6## 7## 1 Redistributions of source code must retain the above copyright notice, 8## this list of conditions and the following disclaimer. 9## 2 Redistributions in binary form must reproduce the above copyright 10## notice, this list of conditions and the following disclaimer in the 11## documentation and/or other materials provided with the distribution. 12## 13## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' 14## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 17## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23## 24## The views and conclusions contained in the software and documentation are 25## those of the authors and should not be interpreted as representing official 26## policies, either expressed or implied, of the copyright holders. 27 28function trans = createTranslation3d(varargin) 29%CREATETRANSLATION3D Create the 4x4 matrix of a 3D translation. 30% 31% usage: 32% TRANS = createTranslation3d(DX, DY, DZ); 33% return the translation corresponding to DX and DY. 34% The returned matrix has the form : 35% [1 0 0 DX] 36% [0 1 0 DY] 37% [0 0 1 DZ] 38% [0 0 0 1] 39% 40% TRANS = createTranslation3d(VECT); 41% return the translation corresponding to the given vector [x y z]. 42% 43% 44% See also: 45% transforms3d, transformPoint3d, transformVector3d, 46% createRotationOx, createRotationOy, createRotationOz, createScaling3d 47% 48% --------- 49% 50% author : David Legland 51% INRA - TPV URPOI - BIA IMASTE 52% created the 06/04/2004. 53% 54 55% HISTORY 56% 22/04/2009 rename as createTranslation3d 57 58 59if isempty(varargin) 60 % assert translation with null vector 61 dx = 0; 62 dy = 0; 63 dz = 0; 64elseif length(varargin)==1 65 % translation vector given in a single argument 66 var = varargin{1}; 67 dx = var(1); 68 dy = var(2); 69 dz = var(3); 70else 71 % translation vector given in 3 arguments 72 dx = varargin{1}; 73 dy = varargin{2}; 74 dz = varargin{3}; 75end 76 77% create the translation matrix 78trans = [1 0 0 dx ; 0 1 0 dy ; 0 0 1 dz; 0 0 0 1]; 79