Home > matGeom > geom3d > eulerAnglesToRotation3d.m

eulerAnglesToRotation3d

PURPOSE ^

EULERANGLESTOROTATION3D Convert 3D Euler angles to 3D rotation matrix.

SYNOPSIS ^

function mat = eulerAnglesToRotation3d(phi, theta, psi, varargin)

DESCRIPTION ^

EULERANGLESTOROTATION3D Convert 3D Euler angles to 3D rotation matrix.

   MAT = eulerAnglesToRotation3d(PHI, THETA, PSI)
   Creates a rotation matrix from the 3 euler angles PHI THETA and PSI,
   given in degrees, using the 'XYZ' convention (local basis), or the
   'ZYX' convention (global basis). The result MAT is a 4-by-4 rotation
   matrix in homogeneous coordinates.

   PHI:    rotation angle around Z-axis, in degrees, corresponding to the
       'Yaw'. PHI is between -180 and +180.
   THETA:  rotation angle around Y-axis, in degrees, corresponding to the
       'Pitch'. THETA is between -90 and +90.
   PSI:    rotation angle around X-axis, in degrees, corresponding to the
       'Roll'. PSI is between -180 and +180.
   These angles correspond to the "Yaw-Pitch-Roll" convention, also known
   as "Tait-Bryan angles".

   The resulting rotation is equivalent to a rotation around X-axis by an
   angle PSI, followed by a rotation around the Y-axis by an angle THETA,
   followed by a rotation around the Z-axis by an angle PHI.
   That is:
       ROT = Rz * Ry * Rx;

   MAT = eulerAnglesToRotation3d(ANGLES)
   Concatenates all angles in a single 1-by-3 array.
   
   ... = eulerAnglesToRotation3d(ANGLES, CONVENTION)
   CONVENTION specifies the axis rotation sequence. Default is 'ZYX'.
   Supported conventions are: 
       'ZYX','ZXY','YXZ','YZX','XYZ','XZY'
       'ZYZ','ZXZ','YZY','YXY','XZX','XYX'

   Example
   [n e f] = createCube;
   phi     = 20;
   theta   = 30;
   psi     = 10;
   rot = eulerAnglesToRotation3d(phi, theta, psi);
   n2 = transformPoint3d(n, rot);
   drawPolyhedron(n2, f);

   See also
   transforms3d, createRotationOx, createRotationOy, createRotationOz
   rotation3dAxisAndAngle

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mat = eulerAnglesToRotation3d(phi, theta, psi, varargin)
0002 %EULERANGLESTOROTATION3D Convert 3D Euler angles to 3D rotation matrix.
0003 %
0004 %   MAT = eulerAnglesToRotation3d(PHI, THETA, PSI)
0005 %   Creates a rotation matrix from the 3 euler angles PHI THETA and PSI,
0006 %   given in degrees, using the 'XYZ' convention (local basis), or the
0007 %   'ZYX' convention (global basis). The result MAT is a 4-by-4 rotation
0008 %   matrix in homogeneous coordinates.
0009 %
0010 %   PHI:    rotation angle around Z-axis, in degrees, corresponding to the
0011 %       'Yaw'. PHI is between -180 and +180.
0012 %   THETA:  rotation angle around Y-axis, in degrees, corresponding to the
0013 %       'Pitch'. THETA is between -90 and +90.
0014 %   PSI:    rotation angle around X-axis, in degrees, corresponding to the
0015 %       'Roll'. PSI is between -180 and +180.
0016 %   These angles correspond to the "Yaw-Pitch-Roll" convention, also known
0017 %   as "Tait-Bryan angles".
0018 %
0019 %   The resulting rotation is equivalent to a rotation around X-axis by an
0020 %   angle PSI, followed by a rotation around the Y-axis by an angle THETA,
0021 %   followed by a rotation around the Z-axis by an angle PHI.
0022 %   That is:
0023 %       ROT = Rz * Ry * Rx;
0024 %
0025 %   MAT = eulerAnglesToRotation3d(ANGLES)
0026 %   Concatenates all angles in a single 1-by-3 array.
0027 %
0028 %   ... = eulerAnglesToRotation3d(ANGLES, CONVENTION)
0029 %   CONVENTION specifies the axis rotation sequence. Default is 'ZYX'.
0030 %   Supported conventions are:
0031 %       'ZYX','ZXY','YXZ','YZX','XYZ','XZY'
0032 %       'ZYZ','ZXZ','YZY','YXY','XZX','XYX'
0033 %
0034 %   Example
0035 %   [n e f] = createCube;
0036 %   phi     = 20;
0037 %   theta   = 30;
0038 %   psi     = 10;
0039 %   rot = eulerAnglesToRotation3d(phi, theta, psi);
0040 %   n2 = transformPoint3d(n, rot);
0041 %   drawPolyhedron(n2, f);
0042 %
0043 %   See also
0044 %   transforms3d, createRotationOx, createRotationOy, createRotationOz
0045 %   rotation3dAxisAndAngle
0046 %
0047 
0048 % ------
0049 % Author: David Legland
0050 % e-mail: david.legland@inra.fr
0051 % Created: 2010-07-22,    using Matlab 7.9.0.529 (R2009b)
0052 % Copyright 2010 INRA - Cepia Software Platform.
0053 
0054 %   HISTORY
0055 %   2011-06-20 rename and use degrees
0056 
0057 % Process input arguments
0058 if size(phi, 2) == 3
0059     if nargin > 1
0060         varargin{1} = theta;
0061     end
0062     % manages arguments given as one array
0063     psi     = phi(:, 3);
0064     theta   = phi(:, 2);
0065     phi     = phi(:, 1);
0066 end
0067 
0068 p = inputParser;
0069 validStrings = {...
0070     'ZYX','ZXY','YXZ','YZX','XYZ','XZY',...
0071     'ZYZ','ZXZ','YZY','YXY','XZX','XYX'};
0072 addOptional(p,'convention','ZYX',@(x) any(validatestring(x,validStrings)));
0073 parse(p,varargin{:});
0074 convention=p.Results.convention;
0075 
0076 % create individual rotation matrices
0077 k = pi / 180;
0078 
0079 switch convention
0080     case 'ZYX'
0081         rot1 = createRotationOx(psi * k);
0082         rot2 = createRotationOy(theta * k);
0083         rot3 = createRotationOz(phi * k);
0084     case 'ZXY'
0085         rot1 = createRotationOy(psi * k);
0086         rot2 = createRotationOx(theta * k);
0087         rot3 = createRotationOz(phi * k);
0088     case 'YXZ'
0089         rot1 = createRotationOz(psi * k);
0090         rot2 = createRotationOx(theta * k);
0091         rot3 = createRotationOy(phi * k);
0092     case 'YZX'
0093         rot1 = createRotationOx(psi * k);
0094         rot2 = createRotationOz(theta * k);
0095         rot3 = createRotationOy(phi * k);
0096     case 'XYZ'
0097         rot1 = createRotationOz(psi * k);
0098         rot2 = createRotationOy(theta * k);
0099         rot3 = createRotationOx(phi * k);
0100     case 'XZY'
0101         rot1 = createRotationOy(psi * k);
0102         rot2 = createRotationOz(theta * k);
0103         rot3 = createRotationOx(phi * k);
0104     case 'ZYZ'
0105         rot1 = createRotationOz(psi * k);
0106         rot2 = createRotationOy(theta * k);
0107         rot3 = createRotationOz(phi * k);
0108     case 'ZXZ'
0109         rot1 = createRotationOz(psi * k);
0110         rot2 = createRotationOx(theta * k);
0111         rot3 = createRotationOz(phi * k);
0112     case 'YZY'
0113         rot1 = createRotationOy(psi * k);
0114         rot2 = createRotationOz(theta * k);
0115         rot3 = createRotationOy(phi * k);
0116     case 'YXY'
0117         rot1 = createRotationOy(psi * k);
0118         rot2 = createRotationOx(theta * k);
0119         rot3 = createRotationOy(phi * k);
0120     case 'XZX'
0121         rot1 = createRotationOx(psi * k);
0122         rot2 = createRotationOz(theta * k);
0123         rot3 = createRotationOx(phi * k);
0124     case 'XYX'
0125         rot1 = createRotationOx(psi * k);
0126         rot2 = createRotationOy(theta * k);
0127         rot3 = createRotationOx(phi * k);
0128 end
0129 
0130 % concatenate matrices
0131 mat = rot3 * rot2 * rot1;

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