Home > matGeom > geom3d > createRotationOx.m

createRotationOx

PURPOSE ^

CREATEROTATIONOX Create the 4x4 matrix of a 3D rotation around x-axis.

SYNOPSIS ^

function trans = createRotationOx(varargin)

DESCRIPTION ^

CREATEROTATIONOX Create the 4x4 matrix of a 3D rotation around x-axis.

   TRANS = createRotationOx(THETA);
   Returns the transform matrix corresponding to a rotation by the angle
   THETA (in radians) around the Ox axis. A rotation by an angle of PI/2
   would transform the vector [0 1 0] into the vector [0 0 1].

   The returned matrix has the form:
   [1      0            0      0]
   [0  cos(THETA) -sin(THETA)  0]
   [0  sin(THETA)  cos(THETA)  0]
   [0      0            0      1]

   TRANS = createRotationOx(ORIGIN, THETA);
   TRANS = createRotationOx(X0, Y0, Z0, THETA);
   Also specifies origin of rotation. The result is similar as performing
   translation(-X0, -Y0, -Z0), rotation, and translation(X0, Y0, Z0).

   See also:
   transforms3d, transformPoint3d, createRotationOy, createRotationOz

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function trans = createRotationOx(varargin)
0002 %CREATEROTATIONOX Create the 4x4 matrix of a 3D rotation around x-axis.
0003 %
0004 %   TRANS = createRotationOx(THETA);
0005 %   Returns the transform matrix corresponding to a rotation by the angle
0006 %   THETA (in radians) around the Ox axis. A rotation by an angle of PI/2
0007 %   would transform the vector [0 1 0] into the vector [0 0 1].
0008 %
0009 %   The returned matrix has the form:
0010 %   [1      0            0      0]
0011 %   [0  cos(THETA) -sin(THETA)  0]
0012 %   [0  sin(THETA)  cos(THETA)  0]
0013 %   [0      0            0      1]
0014 %
0015 %   TRANS = createRotationOx(ORIGIN, THETA);
0016 %   TRANS = createRotationOx(X0, Y0, Z0, THETA);
0017 %   Also specifies origin of rotation. The result is similar as performing
0018 %   translation(-X0, -Y0, -Z0), rotation, and translation(X0, Y0, Z0).
0019 %
0020 %   See also:
0021 %   transforms3d, transformPoint3d, createRotationOy, createRotationOz
0022 %
0023 
0024 %   ---------
0025 %   author : David Legland
0026 %   INRA - TPV URPOI - BIA IMASTE
0027 %   created the 18/02/2005.
0028 %
0029 
0030 %   HISTORY
0031 %   24/11/2008 changed convention for angle
0032 %   22/04/2009 rename as createRotationOx
0033 
0034 
0035 % default values
0036 dx = 0;
0037 dy = 0;
0038 dz = 0;
0039 theta = 0;
0040 
0041 % get input values
0042 if length(varargin) == 1
0043     % only one argument -> rotation angle
0044     theta = varargin{1};
0045     
0046 elseif length(varargin) == 2
0047     % origin point (as array) and angle
0048     var = varargin{1};
0049     dx = var(1);
0050     dy = var(2);
0051     dz = var(3);
0052     theta = varargin{2};
0053     
0054 elseif length(varargin) == 4
0055     % origin (x and y) and angle
0056     dx = varargin{1};
0057     dy = varargin{2};
0058     dz = varargin{3};
0059     theta = varargin{4};
0060 end
0061 
0062 % compute coefs
0063 cot = cos(theta);
0064 sit = sin(theta);
0065 
0066 % create transformation
0067 trans = [...
0068     1 0 0 0;...
0069     0 cot -sit 0;...
0070     0 sit cot 0;...
0071     0 0 0 1];
0072 
0073 % add the translation part
0074 t = [1 0 0 dx;0 1 0 dy;0 0 1 dz;0 0 0 1];
0075 trans = t * trans / t;

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019