V_ROTRO2PL find the plane and rotation angle of a rotation matrix [u,v,t]=r Inputs: R(n,n) Rotation matrix Outputs: U(n,1) and V(n,1) are orthonormal vectors defining a plane in n-dimensional space T is the rotation angle in radians from U towards V with 0<=T<=pi. If T is omitted it U and V will be separated by T instead of being orthogonal
0001 function [u,v,t]=v_rotro2pl(r) 0002 %V_ROTRO2PL find the plane and rotation angle of a rotation matrix [u,v,t]=r 0003 % Inputs: 0004 % 0005 % R(n,n) Rotation matrix 0006 % 0007 % Outputs: 0008 % 0009 % U(n,1) and V(n,1) are orthonormal vectors defining a plane in n-dimensional space 0010 % T is the rotation angle in radians from U towards V with 0<=T<=pi. If T 0011 % is omitted it U and V will be separated by T instead of being orthogonal 0012 0013 % 0014 % Copyright (C) Mike Brookes 2007-2018 0015 % Version: $Id: v_rotro2pl.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 n=size(r,1); 0037 [q,e]=schur(r); 0038 [m,i]=max(abs(e(2:n+1:n^2))); 0039 z=e(i+1,i)<0; % =1 if negative 0040 uv=q(:,i+z:1-2*z:i+1-z); 0041 u=uv(:,1); 0042 % the following code selects unique values of u and v 0043 % v=uv(:,2); 0044 % f=u.*v; % maximize inner product of u.^2 and v.^2 0045 % g=(v+u).*(v-u); 0046 % t=atan2(sum(f.*g),sum(g.^2/4-f.^2))/4; 0047 % c=cos(t); 0048 % s=sin(t); 0049 % uv=uv*[c s; -s c]; 0050 % a=sum(uv)<0; 0051 % uv=uv*[1-a(1)-a(2) a(2)-a(1); a(1)-a(2) 1-a(1)-a(2)]; 0052 % u=uv(:,1); 0053 if nargout>2 0054 v=uv(:,2); 0055 t=atan2(abs(e(i+1,i)),e(i,i)); 0056 elseif nargout 0057 [s,c]=v_atan2sc(abs(e(i+1,i)),e(i,i)); 0058 v=uv*[c;s]; 0059 elseif n==3 % if a 3D rotation 0060 v_rotqr2ro(v_rotro2qr(r)); % plot a rotated cube 0061 end