V_ROTRO2QR converts a 3x3 rotation matrix to look and up directions Inputs: R(3,3,...) Input rotation matrix Outputs: L(3,...) Unit vector specifying look direction U(3,...) Unit vector specifying up direction The rotation maps the look direction to the negative z-axis and the up direction to lie in the y-z plane with a positive y component. That is, R*L=a*[0 0 -1]' and R*U=b*[0 1 c] for postive constants a and b. After applying this rotation to an object, the 2-D data obtained by omitting the z-component represents an orthographic projection performed by a camera looking in the direction L.
0001 function [l,u]=v_rotro2lu(r) 0002 %V_ROTRO2QR converts a 3x3 rotation matrix to look and up directions 0003 % Inputs: R(3,3,...) Input rotation matrix 0004 % 0005 % Outputs: L(3,...) Unit vector specifying look direction 0006 % U(3,...) Unit vector specifying up direction 0007 % 0008 % The rotation maps the look direction to the negative z-axis and the up direction 0009 % to lie in the y-z plane with a positive y component. That is, R*L=a*[0 0 -1]' and 0010 % R*U=b*[0 1 c] for postive constants a and b. After applying this rotation to an object, 0011 % the 2-D data obtained by omitting the z-component represents an orthographic projection 0012 % performed by a camera looking in the direction L. 0013 0014 % Copyright (C) Mike Brookes 2023 0015 % Version: $Id: v_rotro2lu.m 10865 2018-09-21 17:22:45Z dmb $ 0016 % 0017 % VOICEBOX is a MATLAB toolbox for speech processing. 0018 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html 0019 % 0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0021 % This program is free software; you can redistribute it and/or modify 0022 % it under the terms of the GNU General Public License as published by 0023 % the Free Software Foundation; either version 2 of the License, or 0024 % (at your option) any later version. 0025 % 0026 % This program is distributed in the hope that it will be useful, 0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0029 % GNU General Public License for more details. 0030 % 0031 % You can obtain a copy of the GNU General Public License from 0032 % http://www.gnu.org/copyleft/gpl.html or by writing to 0033 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0035 0036 sz=size(r); 0037 r=reshape(r,9,[]); % make 2-dimensional 0038 if size(r,2)>1 % multiple rotation matrices 0039 l=reshape(-r([3 6 9],:),[3 sz(3:end)]); 0040 u=reshape(r([2 5 8],:),[3 sz(3:end)]); 0041 else % only one rotation matrix 0042 l=-r([3 6 9],:); 0043 u=r([2 5 8],:); 0044 end 0045 if ~nargout 0046 v_rotro2qr(reshape(r(:,1),3,3)); % plot a cube 0047 set(gca,'CameraPosition',[0 0 1]); 0048 end