RPY2R Roll/pitch/yaw to rotation matrix R = RPY2R([R P Y]) R = RPY2R(R,P,Y) Returns a 3x3 rotation matrix for the specified roll/pitch/yaw angles. These correspond to rotations about the X, Y, Z axes respectively. NOTE: in previous releases (<8) the angles corresponded to rotations about Z, Y, X. See also: TR2RPY, EUL2TR
0001 %RPY2R Roll/pitch/yaw to rotation matrix 0002 % 0003 % R = RPY2R([R P Y]) 0004 % R = RPY2R(R,P,Y) 0005 % 0006 % Returns a 3x3 rotation matrix for the specified roll/pitch/yaw angles. 0007 % These correspond to rotations about the X, Y, Z axes respectively. 0008 % 0009 % NOTE: in previous releases (<8) the angles corresponded to rotations about Z, Y, X. 0010 % 0011 % See also: TR2RPY, EUL2TR 0012 0013 % Copyright (C) 1993-2008, by Peter I. Corke 0014 % 0015 % This file is part of The Robotics Toolbox for Matlab (RTB). 0016 % 0017 % RTB is free software: you can redistribute it and/or modify 0018 % it under the terms of the GNU Lesser General Public License as published by 0019 % the Free Software Foundation, either version 3 of the License, or 0020 % (at your option) any later version. 0021 % 0022 % RTB is distributed in the hope that it will be useful, 0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0025 % GNU Lesser General Public License for more details. 0026 % 0027 % You should have received a copy of the GNU Leser General Public License 0028 % along with RTB. If not, see <http://www.gnu.org/licenses/>. 0029 0030 function r = rpy2r(roll, pitch, yaw) 0031 if (nargin == 1), 0032 if numcols(roll) ~= 3, 0033 error('bad arguments') 0034 end 0035 pitch = roll(:,2); 0036 yaw = roll(:,3); 0037 roll = roll(:,1); 0038 end 0039 0040 if numrows(roll) == 1, 0041 r = rotx(roll) * roty(pitch) * rotz(yaw); 0042 else 0043 for i=1:numrows(roll), 0044 r(:,:,i) = rotx(roll(i)) * roty(pitch(i)) * rotz(yaw(i)); 0045 end 0046 end