]> Creatis software - CreaPhase.git/blob - octave_packages/quaternion-2.0.0/@quaternion/diff.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / quaternion-2.0.0 / @quaternion / diff.m
1 ## Copyright (c) 1998, 2000, 2005, 2007 Auburn University.
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 ##
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.
8 ##
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.
13 ##
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/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{qdot} =} diff (@var{q}, @var{omega})
19 ## Derivative of a quaternion.
20 ##
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
24 ## of Q is given by
25 ##
26 ## @example
27 ## Q' = diff(Q, omega)
28 ## @end example
29 ##
30 ## If the passive convention is used (rotate the frame, not the vector),
31 ## then
32 ##
33 ## @example
34 ## Q' = diff(Q,-omega)
35 ## @end example
36 ## @end deftypefn
37
38 ## Adapted from: qderiv by A. S. Hodel <a.s.hodel@eng.auburn.edu>
39
40 function qd = diff (q, Omega)
41
42   if (nargin != 2)
43     print_usage ();
44   endif
45
46   if (! isa (q, "quaternion") || ! isscalar (q.w))
47     error ("quaternion: first argument '%s' must be a scalar quaternion", inputname(1));
48   endif
49
50   Omega = vec (Omega);
51
52   if (length (Omega) != 3)
53     error ("quaternion: second argument '%s' must be a length 3 vector", inputname(2));
54   endif
55
56   qd = 0.5 * quaternion (Omega(1), Omega(2), Omega(3)) * q;
57
58 endfunction
59
60 %!shared q
61 %! q = quaternion(3,1,0,0);
62
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]))