changeset 8912:d6e0c71521c3 octave-forge

quaternions_oo . Power vectorized to matrices of quaternions.
author jpicarbajal
date Mon, 14 Nov 2011 22:35:45 +0000
parents 07b5897432b0
children 0177d6f7678e
files extra/quaternion_oo/devel/RV9_Quaternions.txt extra/quaternion_oo/inst/@quaternion/power.m
diffstat 2 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/extra/quaternion_oo/devel/RV9_Quaternions.txt	Mon Nov 14 19:13:11 2011 +0000
+++ b/extra/quaternion_oo/devel/RV9_Quaternions.txt	Mon Nov 14 22:35:45 2011 +0000
@@ -106,9 +106,9 @@
 
 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.
+DONE  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
+DONE  Q = Quaternion(T) is a unit quaternion equivalent to the rotational
 
 = methods =
 DONE [c] inv       return inverse of quaterion
--- a/extra/quaternion_oo/inst/@quaternion/power.m	Mon Nov 14 19:13:11 2011 +0000
+++ b/extra/quaternion_oo/inst/@quaternion/power.m	Mon Nov 14 22:35:45 2011 +0000
@@ -33,7 +33,8 @@
     a.x = -a.x ./ norm2;
     a.y = -a.y ./ norm2;
     a.z = -a.z ./ norm2;
-  else
+
+  elseif isvector (a.w)
 
     na = abs (a);
     th = acos (a.w ./ na);
@@ -47,6 +48,23 @@
     a.y = n(:,2) .* nab .* snt;
     a.z = n(:,3) .* nab .* snt;
 
+  else
+
+    na = abs (a);
+    th = acos (a.w ./ na);
+    nv = sqrt ((a.x).^2 + (a.y).^2 + (a.z).^2);
+    n.x = a.x ./ nv;
+    n.y = a.y ./ nv;
+    n.z = a.z ./ nv;
+
+    nab = na.^b;
+    a.w = nab .* cos (b.*th);
+
+    snt = sin (b.*th);
+    a.x = n.x .* nab .* snt;
+    a.y = n.y .* nab .* snt;
+    a.z = n.z .* nab .* snt;
+
   endif
 
 endfunction