1 ## Copyright (c) 1998, 2000, 2005, 2007 Auburn University.
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
4 ## This program is free software: you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation, either version 3 of the License, or
7 ## (at your option) any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} {@var{qdot} =} diff (@var{q}, @var{omega})
19 ## Derivative of a quaternion.
21 ## Let Q be a quaternion to transform a vector from a fixed frame to
22 ## a rotating frame. If the rotating frame is rotating about the
23 ## [x, y, z] axes at angular rates [wx, wy, wz], then the derivative
27 ## Q' = diff(Q, omega)
30 ## If the passive convention is used (rotate the frame, not the vector),
34 ## Q' = diff(Q,-omega)
38 ## Adapted from: qderiv by A. S. Hodel <a.s.hodel@eng.auburn.edu>
40 function qd = diff (q, Omega)
46 if (! isa (q, "quaternion") || ! isscalar (q.w))
47 error ("quaternion: first argument '%s' must be a scalar quaternion", inputname(1));
52 if (length (Omega) != 3)
53 error ("quaternion: second argument '%s' must be a length 3 vector", inputname(2));
56 qd = 0.5 * quaternion (Omega(1), Omega(2), Omega(3)) * q;
61 %! q = quaternion(3,1,0,0);
63 %!assert(quaternion(0,0,0.5,1.5) == diff(q,[0 0 1]))
64 %!assert(quaternion(0,0,2,1) == diff(q,[0 1 1]))