# v_roteu2ro

## PURPOSE

V_ROTEU2QR converts a sequence of Euler angles to a rotation matrix

## SYNOPSIS

function r=v_roteu2ro(varargin)

## DESCRIPTION

    V_ROTEU2QR converts a sequence of Euler angles to a rotation matrix
     Inputs:

         M        a string of n characters from the set determining the order of rotation axes
                  as listed below:
                    'x','y','z'    rotate around the given axis by the corresponding angle
                                   given in e()
                    '1','2','3'    90 degree rotation around x,y or z axis; doesn't use a value from e()
                    '4','5','6'    180 degree rotation around x,y or z axis; doesn't use a value from e()
                    '7','8','9'    270 degree rotation around x,y or z axis; doesn't use a value from e()
                    'r','d'        all angles are given in radians or degrees  [default='r']
                    'R','D'        all angles are given in radians or degrees and are negated
                 'o','O','a','A'   selects whether to rotate the object or the coordinate axes and
                                   whether the rotation axes remain fixed in space for consecutive
                                   rotations (extrinsic) or else move with each rotation (intrinsic).
                                      'o' = object-extrinsic [default]
                                      'O' = object-intrinsic
                                      'a' = axes-extrinsic
                                      'A' = axes-intrinsic

         E(K,...)  K Euler angles in radians (or degrees if 'd' or 'D' specified) per quaternion where K is the number of 'xyz' characters in M.
                   A positive rotation is clockwise if looking along the +ve axis away from the origin or anti-clockwise if 'R' or 'D' is given.
                   The x, y, z axes form a right-handed triple.

     Outputs:

         R(3,3,...)   Output rotation matrix
                  Plots a diagram if no output specified

     The string M specifies the seqeunce of axes about which the rotations are performed. There are 12
     possible 3-character sequences that avoid consecutive repetitions. These are 'Euler angles' if
     there is a repeated axis or 'Tait-Bryan angles' if not. Common choices are:
     (1) 'zxz' the most common Euler angle set
     (2) 'xyz' corresponds to 'roll, pitch, yaw' for an aeroplane heading in the x direction with y to
         the right and z down. The intrinsic equivalent is 'Ozyx' corresponding to 'yaw, pitch, roll'.
     (3) 'z1z1z' involves 5 rotations, in which all the non-fixed rotations are around the z axis.

     The Euler angles are not, in general, unique. In particular the following equivalences exist:
      (1) v_roteu2ro('zxz',[a b c]) = v_roteu2ro('zxz',[a+pi -b c+pi])
      (2) v_roteu2ro('xyz',[a b c]) = v_roteu2ro('zxz',[a+pi pi-b c+pi])
      (3) v_roteu2ro('456',[]) = eye(3) % also true for any ordering of '456'
      (4) v_roteu2ro('x',a) = v_roteu2ro('5x5',-a) = v_roteu2ro('5x6',pi-a) % also true if 5,6 are interchanged

## CROSS-REFERENCE INFORMATION

This function calls:

- v_roteu2qr ROTEU2QR converts a sequence of Euler angles to a real unit quaternion
- v_rotqr2ro ROTQR2RO converts a real quaternion to a 3x3 rotation matrix

This function is called by:

## SOURCE CODE

    0001 function r=v_roteu2ro(varargin)
    0002 %V_ROTEU2QR converts a sequence of Euler angles to a rotation matrix
    0003 % Inputs:
    0004 %
    0005 %     M        a string of n characters from the set determining the order of rotation axes
    0006 %              as listed below:
    0007 %                'x','y','z'    rotate around the given axis by the corresponding angle
    0008 %                               given in e()
    0009 %                '1','2','3'    90 degree rotation around x,y or z axis; doesn't use a value from e()
    0010 %                '4','5','6'    180 degree rotation around x,y or z axis; doesn't use a value from e()
    0011 %                '7','8','9'    270 degree rotation around x,y or z axis; doesn't use a value from e()
    0012 %                'r','d'        all angles are given in radians or degrees  [default='r']
    0013 %                'R','D'        all angles are given in radians or degrees and are negated
    0014 %             'o','O','a','A'   selects whether to rotate the object or the coordinate axes and
    0015 %                               whether the rotation axes remain fixed in space for consecutive
    0016 %                               rotations (extrinsic) or else move with each rotation (intrinsic).
    0017 %                                  'o' = object-extrinsic [default]
    0018 %                                  'O' = object-intrinsic
    0019 %                                  'a' = axes-extrinsic
    0020 %                                  'A' = axes-intrinsic
    0021 %
    0022 %     E(K,...)  K Euler angles in radians (or degrees if 'd' or 'D' specified) per quaternion where K is the number of 'xyz' characters in M.
    0023 %               A positive rotation is clockwise if looking along the +ve axis away from the origin or anti-clockwise if 'R' or 'D' is given.
    0024 %               The x, y, z axes form a right-handed triple.
    0025 %
    0026 % Outputs:
    0027 %
    0028 %     R(3,3,...)   Output rotation matrix
    0029 %              Plots a diagram if no output specified
    0030 %
    0031 % The string M specifies the seqeunce of axes about which the rotations are performed. There are 12
    0032 % possible 3-character sequences that avoid consecutive repetitions. These are 'Euler angles' if
    0033 % there is a repeated axis or 'Tait-Bryan angles' if not. Common choices are:
    0034 % (1) 'zxz' the most common Euler angle set
    0035 % (2) 'xyz' corresponds to 'roll, pitch, yaw' for an aeroplane heading in the x direction with y to
    0036 %     the right and z down. The intrinsic equivalent is 'Ozyx' corresponding to 'yaw, pitch, roll'.
    0037 % (3) 'z1z1z' involves 5 rotations, in which all the non-fixed rotations are around the z axis.
    0038 %
    0039 % The Euler angles are not, in general, unique. In particular the following equivalences exist:
    0040 %  (1) v_roteu2ro('zxz',[a b c]) = v_roteu2ro('zxz',[a+pi -b c+pi])
    0041 %  (2) v_roteu2ro('xyz',[a b c]) = v_roteu2ro('zxz',[a+pi pi-b c+pi])
    0042 %  (3) v_roteu2ro('456',[]) = eye(3) % also true for any ordering of '456'
    0043 %  (4) v_roteu2ro('x',a) = v_roteu2ro('5x5',-a) = v_roteu2ro('5x6',pi-a) % also true if 5,6 are interchanged
    0044
    0045 %      Copyright (C) Mike Brookes 2007-2020
    0046 %      Version: $Id: v_roteu2ro.m 11260 2020-07-18 20:07:58Z dmb $
    0047 %
    0048 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0049 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0050 %
    0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0052 %   This program is free software; you can redistribute it and/or modify
    0053 %   it under the terms of the GNU Lesser General Public License as published by
    0054 %   the Free Software Foundation; either version 3 of the License, or
    0055 %   (at your option) any later version.
    0056 %
    0057 %   This program is distributed in the hope that it will be useful,
    0058 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0059 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0060 %   GNU Lesser General Public License for more details.
    0061 %
    0062 %   You can obtain a copy of the GNU Lesser General Public License from
    0063 %   https://www.gnu.org/licenses/ .
    0064 %
    0065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0066 if nargout
    0067     r=v_rotqr2ro(v_roteu2qr(varargin{:}));
    0068 else
    0069     v_rotqr2ro(v_roteu2qr(varargin{:})); % draw a cube
    0070 end