Home > @quaternion > qinterp.m

qinterp

PURPOSE ^

QINTERP Interpolate rotations expressed by quaternion objects

SYNOPSIS ^

function q = qinterp(Q1, Q2, r)

DESCRIPTION ^

QINTERP Interpolate rotations expressed by quaternion objects

    QI = qinterp(Q1, Q2, R)

 Return a unit-quaternion that interpolates between Q1 and Q2 as R moves
 from 0 to 1.  This is a spherical linear interpolation (slerp) that can
 be interpretted as interpolation along a great circle arc on a sphere.

 If r is a vector, QI, is a cell array of quaternions, each element
 corresponding to sequential elements of R.

 See also: CTRAJ, QUATERNION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %QINTERP Interpolate rotations expressed by quaternion objects
0002 %
0003 %    QI = qinterp(Q1, Q2, R)
0004 %
0005 % Return a unit-quaternion that interpolates between Q1 and Q2 as R moves
0006 % from 0 to 1.  This is a spherical linear interpolation (slerp) that can
0007 % be interpretted as interpolation along a great circle arc on a sphere.
0008 %
0009 % If r is a vector, QI, is a cell array of quaternions, each element
0010 % corresponding to sequential elements of R.
0011 %
0012 % See also: CTRAJ, QUATERNION.
0013 
0014 % Copyright (C) 1999-2008, by Peter I. Corke
0015 %
0016 % This file is part of The Robotics Toolbox for Matlab (RTB).
0017 %
0018 % RTB is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU Lesser General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % RTB is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU Lesser General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU Leser General Public License
0029 % along with RTB.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 function q = qinterp(Q1, Q2, r)
0032 
0033 
0034     q1 = double(Q1);
0035     q2 = double(Q2);
0036 
0037     if (r<0) | (r>1),
0038         error('R out of range');
0039     end
0040 
0041     theta = acos(q1*q2');
0042     q = {};
0043     count = 1;
0044 
0045     if length(r) == 1,
0046         if theta == 0,
0047             q = Q1;
0048         else
0049             q = quaternion( (sin((1-r)*theta) * q1 + sin(r*theta) * q2) / sin(theta) );
0050         end
0051     else
0052         for R=r(:)',
0053             if theta == 0,
0054                 qq = Q1;
0055             else
0056                 qq = quaternion( (sin((1-R)*theta) * q1 + sin(R*theta) * q2) / sin(theta) );
0057             end
0058             q{count} = qq;
0059             count = count + 1;
0060         end
0061     end

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