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 % E-mail: david.legland@inrae.fr
0027 % Created: 2005-02-18
0028 % Copyright 2005-2024 INRA - TPV URPOI - BIA IMASTE
0029 
0030 % default values
0031 dx = 0;
0032 dy = 0;
0033 dz = 0;
0034 theta = 0;
0035 
0036 % get input values
0037 if isscalar(varargin)
0038     % only one argument -> rotation angle
0039     theta = varargin{1};
0040     
0041 elseif length(varargin) == 2
0042     % origin point (as array) and angle
0043     var = varargin{1};
0044     dx = var(1);
0045     dy = var(2);
0046     dz = var(3);
0047     theta = varargin{2};
0048     
0049 elseif length(varargin) == 4
0050     % origin (x and y) and angle
0051     dx = varargin{1};
0052     dy = varargin{2};
0053     dz = varargin{3};
0054     theta = varargin{4};
0055 end
0056 
0057 % compute coefs
0058 cot = cos(theta);
0059 sit = sin(theta);
0060 
0061 % create transformation
0062 trans = [...
0063     1 0 0 0;...
0064     0 cot -sit 0;...
0065     0 sit cot 0;...
0066     0 0 0 1];
0067 
0068 % add the translation part
0069 t = [1 0 0 dx;0 1 0 dy;0 0 1 dz;0 0 0 1];
0070 trans = t * trans / t;

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022