Home > @quaternion > subsref.m

subsref

PURPOSE ^

SUBSREF Reference methods on a QUATERNION object

SYNOPSIS ^

function v = subsref(q, s)

DESCRIPTION ^

SUBSREF Reference methods on a QUATERNION object

    QUATERNION.d        return a 4-vector of quaternion elements
    QUATERNION.s        return the scalar component
    QUATERNION.v        return the vector component
    QUATERNION.t        return a 4x4 homogeneous transform
    QUATERNION.r        return a 3x3 orthonormal rotation matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %SUBSREF Reference methods on a QUATERNION object
0002 %
0003 %    QUATERNION.d        return a 4-vector of quaternion elements
0004 %    QUATERNION.s        return the scalar component
0005 %    QUATERNION.v        return the vector component
0006 %    QUATERNION.t        return a 4x4 homogeneous transform
0007 %    QUATERNION.r        return a 3x3 orthonormal rotation matrix
0008 
0009 % Copyright (C) 1999-2008, by Peter I. Corke
0010 %
0011 % This file is part of The Robotics Toolbox for Matlab (RTB).
0012 %
0013 % RTB is free software: you can redistribute it and/or modify
0014 % it under the terms of the GNU Lesser General Public License as published by
0015 % the Free Software Foundation, either version 3 of the License, or
0016 % (at your option) any later version.
0017 %
0018 % RTB is distributed in the hope that it will be useful,
0019 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0020 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021 % GNU Lesser General Public License for more details.
0022 %
0023 % You should have received a copy of the GNU Leser General Public License
0024 % along with RTB.  If not, see <http://www.gnu.org/licenses/>.
0025 
0026 function v = subsref(q, s)
0027     if s(1).type  == '.'
0028 
0029         % NOTE WELL:  the following code can't use getfield() since
0030         % getfield()  uses this, and Matlab will crash!!
0031 
0032         el = char(s(1).subs);
0033         switch el,
0034         case 'd',
0035             v = double(q);
0036         case 's',
0037             v = q.s;
0038         case 'v',
0039             v = q.v;
0040         case 't',
0041             v = q2tr(q);
0042         case 'r',
0043             v = q2tr(q);
0044             v = v(1:3,1:3);
0045         end
0046     else
0047         error('only .field supported')
0048     end
0049 
0050 %Q2TR    Convert unit-quaternion to homogeneous transform
0051 %
0052 %    T = q2tr(Q)
0053 %
0054 %    Return the rotational homogeneous transform corresponding to the unit
0055 %    quaternion Q.
0056 %
0057 %    See also: TR2Q
0058 
0059 %    Copyright (C) 1993 Peter Corke
0060 function t = q2tr(q)
0061 
0062     q = double(q);
0063     s = q(1);
0064     x = q(2);
0065     y = q(3);
0066     z = q(4);
0067 
0068     r = [    1-2*(y^2+z^2)    2*(x*y-s*z)    2*(x*z+s*y)
0069         2*(x*y+s*z)    1-2*(x^2+z^2)    2*(y*z-s*x)
0070         2*(x*z-s*y)    2*(y*z+s*x)    1-2*(x^2+y^2)    ];
0071     t = eye(4,4);
0072     t(1:3,1:3) = r;
0073     t(4,4) = 1;

Generated on Sun 15-Feb-2009 18:09:29 by m2html © 2003