Home > matGeom > geom3d > createRotationOz.m

createRotationOz

PURPOSE ^

CREATEROTATIONOZ Create the 4x4 matrix of a 3D rotation around z-axis.

SYNOPSIS ^

function trans = createRotationOz(varargin)

DESCRIPTION ^

CREATEROTATIONOZ Create the 4x4 matrix of a 3D rotation around z-axis.

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

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

   TRANS = createRotationOz(ORIGIN, THETA);
   TRANS = createRotationOz(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, createRotationOx, createRotationOy

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function trans = createRotationOz(varargin)
0002 %CREATEROTATIONOZ Create the 4x4 matrix of a 3D rotation around z-axis.
0003 %
0004 %   TRANS = createRotationOz(THETA);
0005 %   Returns the transform matrix corresponding to a rotation by the angle
0006 %   THETA (in radians) around the Oz axis. A rotation by an angle of PI/2
0007 %   would transform the vector [1 0 0] into the vector [0 1 0].
0008 %
0009 %   The returned matrix has the form:
0010 %   [cos(THETA) -sin(THETA)  0  0]
0011 %   [sin(THETA)  cos(THETA)  0  0]
0012 %   [    0           0       1  0]
0013 %   [    0           0       0  1]
0014 %
0015 %   TRANS = createRotationOz(ORIGIN, THETA);
0016 %   TRANS = createRotationOz(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 %
0021 %   See also
0022 %   transforms3d, transformPoint3d, createRotationOx, createRotationOy
0023 %
0024 
0025 % ------
0026 % Author: David Legland
0027 % E-mail: david.legland@inrae.fr
0028 % Created: 2004-04-06
0029 % Copyright 2004-2024 INRA - TPV URPOI - BIA IMASTE
0030 
0031 % default values
0032 dx = 0;
0033 dy = 0;
0034 dz = 0;
0035 theta = 0;
0036 
0037 % get input values
0038 if isscalar(varargin)
0039     % only one argument -> rotation angle
0040     theta = varargin{1};
0041     
0042 elseif length(varargin) == 2
0043     % origin point (as array) and angle
0044     var = varargin{1};
0045     dx = var(1);
0046     dy = var(2);
0047     dz = var(3);
0048     theta = varargin{2};
0049     
0050 elseif length(varargin) == 4
0051     % origin (x and y) and angle
0052     dx = varargin{1};
0053     dy = varargin{2};
0054     dz = varargin{3};
0055     theta = varargin{4};
0056 end
0057 
0058 % compute coefs
0059 cot = cos(theta);
0060 sit = sin(theta);
0061 
0062 % create transformation
0063 trans = [...
0064     cot -sit 0 0;...
0065     sit  cot 0 0;...
0066     0 0 1 0;...
0067     0 0 0 1];
0068 
0069 % add the translation part
0070 t = [1 0 0 dx;0 1 0 dy;0 0 1 dz;0 0 0 1];
0071 trans = t * trans / t;

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