Home > voicebox > rotpl2ro.m

rotpl2ro

PURPOSE ^

ROTPL2RO find matrix to rotate in the plane containing u and v r=[u,v,t]

SYNOPSIS ^

function r=rotpl2ro(u,v,t)

DESCRIPTION ^

ROTPL2RO find matrix to rotate in the plane containing u and v r=[u,v,t]
 Inputs:

     U(n,1) and V(n,1) define a plane in n-dimensional space
     T is the rotation angle in radians from U towards V. If T
       is omitted it will default to the angle between U and V

 Outputs:

     R(n,n)   Rotation matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function r=rotpl2ro(u,v,t)
0002 %ROTPL2RO find matrix to rotate in the plane containing u and v r=[u,v,t]
0003 % Inputs:
0004 %
0005 %     U(n,1) and V(n,1) define a plane in n-dimensional space
0006 %     T is the rotation angle in radians from U towards V. If T
0007 %       is omitted it will default to the angle between U and V
0008 %
0009 % Outputs:
0010 %
0011 %     R(n,n)   Rotation matrix
0012 
0013 %
0014 %      Copyright (C) Mike Brookes 2007
0015 %      Version: $Id: rotpl2ro.m 713 2011-10-16 14:45:43Z 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 u=u(:);
0037     n=length(u);
0038 v=v(:);
0039 l=sqrt(u'*u);
0040 if l==0, error('input u is a zero vector'); end
0041 u=u/l;      % normalize
0042 q=v-v'*u*u;        % q is orthogonal to x
0043 l=sqrt(q'*q);
0044 if l==0          % u and v are colinear or v=zero
0045     [m,i]=max(abs(u));
0046     q=zeros(n,1);
0047     q(1+mod(i(1),n))=1;  % choose next available dimension
0048     q=q-q'*u*u;  % q is orthogonal to x
0049     l=sqrt(q'*q);
0050 end
0051 q=q/l;          % normalize
0052 if nargin<3
0053     [s,c]=atan2sc(v'*q,v'*u);
0054     r=eye(n)+(c-1)*(u*u'+q*q')+s*(q*u'-u*q');
0055 else
0056     r=eye(n)+(cos(t)-1)*(u*u'+q*q')+sin(t)*(q*u'-u*q');
0057 end
0058

Generated on Tue 10-Oct-2017 08:30:10 by m2html © 2003