changeset 8901:d93624c61740 octave-forge

quaternion_oo . Adding time derivative of a quaternion as method with tests To test use: test @quaternion/dot after the object oriented version of quaternion was installed.
author jpicarbajal
date Mon, 14 Nov 2011 14:54:28 +0000
parents eaef0b2ef2e8
children 8b328abf65b6
files extra/quaternion_oo/devel/RV9_Quaternions.txt extra/quaternion_oo/inst/@quaternion/dot.m
diffstat 2 files changed, 83 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/extra/quaternion_oo/devel/RV9_Quaternions.txt	Mon Nov 14 14:53:49 2011 +0000
+++ b/extra/quaternion_oo/devel/RV9_Quaternions.txt	Mon Nov 14 14:54:28 2011 +0000
@@ -94,6 +94,21 @@
 We hope not to run into the c tag.
 
 == Quaternion ==
+DONE  Q = Quaternion() is the identitity quaternion 1<0,0,0> representing a null rotation.
+
+DONE  Q = Quaternion(Q1) is a copy of the quaternion Q1
+
+DONE  Q = Quaternion([S V1 V2 V3]) is a quaternion formed by specifying directly its 4 elements
+
+DONE  Q = Quaternion(S) is a quaternion formed from the scalar S and zero vector part: S<0,0,0>
+
+DONE  Q = Quaternion(V) is a pure quaternion with the specified vector part: 0<V>
+
+DONE  Q = Quaternion(TH, V) is a unit quaternion corresponding to rotation of TH about the vector V.
+
+ Q = Quaternion(R) is a unit quaternion corresponding to the orthonormal rotation matrix R.
+
+ Q = Quaternion(T) is a unit quaternion equivalent to the rotational
 
 = methods =
 
@@ -101,14 +116,13 @@
 By Monday, November 07 2011 this function is equivalent to the conj function of quaternions_oo
 not to inv of that package.
 
-DONE [e] norm:  We will wrap abs from quaternions_oo
+DONE [e] norm:  Wraps abs from quaternions_oo
 
-[] unit      return unit quaternion
-[] unitize   unitize this quaternion
+DONE [] unit      return unit quaternion
 [] plot      same options as trplot()
 [] interp    interpolation (slerp) between q and q2, 0<=s<=1
 [] scale     interpolation (slerp) between identity and q, 0<=s<=1
-[] dot       derivative of quaternion with angular velocity w
+DONE [x] dot  derivative of quaternion with angular velocity w
 
 = Operators =
 [*] q+q2      return elementwise sum of quaternions
@@ -120,7 +134,7 @@
 [] q^n       return q to power n (integer only)
 
 = Properties (read only)=
-[] s         real part
-[] v         vector part
-[] R         3x3 rotation matrix
-[] T         4x4 homogeneous transform matrix
+DONE [] s         real part
+DONE [] v         vector part
+DONE [] R         3x3 rotation matrix
+DONE [] T         4x4 homogeneous transform matrix
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/quaternion_oo/inst/@quaternion/dot.m	Mon Nov 14 14:54:28 2011 +0000
@@ -0,0 +1,61 @@
+%% Copyright (c) 1998, 2000, 2005, 2007 Auburn University.
+%% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
+%%
+%%    This program is free software: you can redistribute it and/or modify
+%%    it under the terms of the GNU General Public License as published by
+%%    the Free Software Foundation, either version 3 of the License, or
+%%    any later version.
+%%
+%%    This program is distributed in the hope that it will be useful,
+%%    but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%%    GNU General Public License for more details.
+%%
+%%    You should have received a copy of the GNU General Public License
+%%    along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+%% -*- texinfo -*-
+%% @deftypefn {Function File} {} dot (q, omega)
+%% Derivative of a quaternion.
+%%
+%% Let Q be a quaternion to transform a vector from a fixed frame to
+%% a rotating frame.  If the rotating frame is rotating about the
+%% [x, y, z] axes at angular rates [wx, wy, wz], then the derivative
+%% of Q is given by
+%%
+%% @example
+%% Q' = dot(Q, omega)
+%% @end example
+%%
+%% If the passive convention is used (rotate the frame, not the vector),
+%% then
+%%
+%% @example
+%% Q' = dot(Q,-omega)
+%% @end example
+%% @end deftypefn
+
+%% Adapted from: qderiv by A. S. Hodel <a.s.hodel@eng.auburn.edu>
+
+function qd = dot (q, Omega)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  Omega = vec (Omega);
+
+  if (length (Omega) != 3)
+    error ("Quaternion:InvalidArgument: Omega must be a length 3 vector");
+  endif
+
+  qd = 0.5 * quaternion(Omega(1),Omega(2),Omega(3)) * q;
+
+endfunction
+
+%!shared q
+%! q = quaternion(3,1,0,0);
+
+%!assert(quaternion(0,0,0.5,1.5) == dot(q,[0 0 1]))
+%!assert(quaternion(0,0,2,1) == dot(q,[0 1 1]))
+