Home > matGeom > geom3d > createRotation3dLineAngle.m

createRotation3dLineAngle

PURPOSE ^

CREATEROTATION3DLINEANGLE Create rotation around a line by an angle theta.

SYNOPSIS ^

function mat = createRotation3dLineAngle(line, theta)

DESCRIPTION ^

CREATEROTATION3DLINEANGLE Create rotation around a line by an angle theta.

   MAT = createRotation3dLineAngle(LINE, ANGLE)

   Example
     origin = [1 2 3];
     direction = [4 5 6];
     line = [origin direction];
     angle = pi/3;
     rot = createRotation3dLineAngle(line, angle);
     [axis angle2] = rotation3dAxisAndAngle(rot);
     angle2
     angle2 =
           1.0472

   See also
   transforms3d, rotation3dAxisAndAngle, rotation3dToEulerAngles,
   eulerAnglesToRotation3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mat = createRotation3dLineAngle(line, theta)
0002 %CREATEROTATION3DLINEANGLE Create rotation around a line by an angle theta.
0003 %
0004 %   MAT = createRotation3dLineAngle(LINE, ANGLE)
0005 %
0006 %   Example
0007 %     origin = [1 2 3];
0008 %     direction = [4 5 6];
0009 %     line = [origin direction];
0010 %     angle = pi/3;
0011 %     rot = createRotation3dLineAngle(line, angle);
0012 %     [axis angle2] = rotation3dAxisAndAngle(rot);
0013 %     angle2
0014 %     angle2 =
0015 %           1.0472
0016 %
0017 %   See also
0018 %   transforms3d, rotation3dAxisAndAngle, rotation3dToEulerAngles,
0019 %   eulerAnglesToRotation3d
0020 %
0021 
0022 % ------
0023 % Author: David Legland
0024 % e-mail: david.legland@inra.fr
0025 % Created: 2010-08-11,    using Matlab 7.9.0.529 (R2009b)
0026 % Copyright 2010 INRA - Cepia Software Platform.
0027 
0028 % determine rotation center and direction
0029 center = [0 0 0];
0030 if size(line, 2)==6
0031     center = line(1:3);
0032     vector = line(4:6);
0033 else
0034     vector = line;
0035 end
0036 
0037 % normalize vector
0038 v = normalizeVector3d(vector);
0039 
0040 % compute projection matrix P and anti-projection matrix
0041 P = v'*v;
0042 Q = [0 -v(3) v(2) ; v(3) 0 -v(1) ; -v(2) v(1) 0];
0043 I = eye(3);
0044 
0045 % compute vectorial part of the transform
0046 mat = eye(4);
0047 mat(1:3, 1:3) = P + (I - P)*cos(theta) + Q*sin(theta);
0048 
0049 % add translation coefficient
0050 mat = recenterTransform3d(mat, center);

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