1 ## Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006, 2007 Auburn University
2 ## Copyright (C) 2010, 2011 Lukas F. Reichlin
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{axis}, @var{angle}] =} q2rot (@var{q})
19 ## Extract vector/angle form of a unit quaternion @var{q}.
24 ## Unit quaternion describing the rotation.
30 ## Eigenaxis as a 3-d unit vector @code{[x, y, z]}.
32 ## Rotation angle in radians. The positive direction is
33 ## determined by the right-hand rule applied to @var{axis}.
39 ## octave:1> axis = [0, 0, 1]
42 ## octave:2> angle = pi/4
44 ## octave:3> q = rot2q (axis, angle)
45 ## q = 0.9239 + 0i + 0j + 0.3827k
46 ## octave:4> [vv, th] = q2rot (q)
50 ## octave:5> theta = th*180/pi
58 ## Adapted from: quaternion by A. S. Hodel <a.s.hodel@eng.auburn.edu>
59 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
63 function [vv, theta] = q2rot (q)
65 if (nargin != 1 || nargout != 2)
69 if (! isa (q, "quaternion") || ! isscalar (q.w))
70 error ("q2rot: require scalar quaternion as input");
73 if (abs (norm (q) - 1) > 1e-12)
74 warning ("q2rot: ||q||=%e, setting=1 for vv, theta", norm (q));
84 theta = theta - sign (theta) * pi;