Mercurial > forge
changeset 8906:c0bfe654cd65 octave-forge
quaternions_oo . power function implemented
author | jpicarbajal |
---|---|
date | Mon, 14 Nov 2011 16:34:11 +0000 |
parents | cac88c349f8f |
children | aee6fd8e754b |
files | extra/quaternion_oo/devel/RV9_Quaternions.txt extra/quaternion_oo/inst/@quaternion/power.m |
diffstat | 2 files changed, 29 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/quaternion_oo/devel/RV9_Quaternions.txt Mon Nov 14 16:24:51 2011 +0000 +++ b/extra/quaternion_oo/devel/RV9_Quaternions.txt Mon Nov 14 16:34:11 2011 +0000 @@ -111,26 +111,24 @@ Q = Quaternion(T) is a unit quaternion equivalent to the rotational = methods = +DONE [c] inv return inverse of quaterion +DONE [e] norm: Wraps abs from quaternions_oo +DONE [x] dot derivative of quaternion with angular velocity w +DONE [c] display +DONE [] q2tr +DONE [*] unit return unit quaternion -DONE [c] inv return inverse of quaterion -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: Wraps abs from quaternions_oo - -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 -DONE [x] dot derivative of quaternion with angular velocity w = Operators = -[*] q+q2 return elementwise sum of quaternions -[*] q-q2 return elementwise difference of quaternions -[*] q*q2 return quaternion product +DONE [*] q+q2 return elementwise sum of quaternions +DONE [*] q-q2 return elementwise difference of quaternions +DONE [*] q*q2 return quaternion product +DONE [*] q/q2 return q*q2.inv + [*] q*v rotate vector by quaternion, v is 3x1 -[*] q/q2 return q*q2.inv - [] q^n return q to power n (integer only) = Properties (read only)=
--- a/extra/quaternion_oo/inst/@quaternion/power.m Mon Nov 14 16:24:51 2011 +0000 +++ b/extra/quaternion_oo/inst/@quaternion/power.m Mon Nov 14 16:34:11 2011 +0000 @@ -23,6 +23,10 @@ function a = power (a, b) + if !isreal(b) + error('quaternion:InvalidArgument','Exponent must be real'); + end + if (b == -1 && isa (a, "quaternion")) norm2 = norm2 (a); a.w = a.w ./ norm2; @@ -30,9 +34,19 @@ a.y = -a.y ./ norm2; a.z = -a.z ./ norm2; else - error ("quaternion: power: case not implemeted"); + + na = abs (a); + th = acos (a.w / na); + n = [a.x a.y a.z] ./ sqrt((a.x).^2 + (a.y).^2 + (a.z).^2); + + nab = na.^b; + a.w = nab .* cos (b.*th); + + snt = sin (b.*th); + a.x = n(:,1) .* nab .* snt; + a.y = n(:,2) .* nab .* snt; + a.z = n(:,3) .* nab .* snt; + endif - ## TODO: q1 .^ q2 - -endfunction \ No newline at end of file +endfunction