From: <par...@us...> - 2011-11-13 13:32:42
|
Revision: 9074 http://octave.svn.sourceforge.net/octave/?rev=9074&view=rev Author: paramaniac Date: 2011-11-13 13:32:36 +0000 (Sun, 13 Nov 2011) Log Message: ----------- quaternion-oo: add unit method, various enhancements Modified Paths: -------------- trunk/octave-forge/extra/quaternion_oo/INDEX trunk/octave-forge/extra/quaternion_oo/devel/demoml.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/abs.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/columns.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/inv.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/mpower.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/power.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/rows.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/size.m Added Paths: ----------- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/private/ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/private/norm2.m trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/unit.m Modified: trunk/octave-forge/extra/quaternion_oo/INDEX =================================================================== --- trunk/octave-forge/extra/quaternion_oo/INDEX 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/INDEX 2011-11-13 13:32:36 UTC (rev 9074) @@ -8,6 +8,7 @@ @quaternion/rows @quaternion/columns @quaternion/size + @quaternion/unit Overloaded and Arithmetic Operators @quaternion/plus @quaternion/minus Modified: trunk/octave-forge/extra/quaternion_oo/devel/demoml.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/devel/demoml.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/devel/demoml.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,10 +1,10 @@ q = rot2q ([0, 0, 1], pi/4) -% [vv, theta] = q2rot (q) +[vv, theta] = q2rot (q) x = quaternion (0, 1, 1, 0) % nicht normiert % s x y z rx = q * x * conj (q) % q x q^-1 -% [vv, theta] = q2rot (rx) +[vv, theta] = q2rot (rx) Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/abs.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/abs.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/abs.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,4 +1,4 @@ -## Copyright (C) 2010 Lukas F. Reichlin +## Copyright (C) 2010, 2011 Lukas F. Reichlin ## ## 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 @@ -25,7 +25,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: August 2010 -## Version: 0.1 +## Version: 0.2 function b = abs (a) @@ -34,6 +34,6 @@ print_usage (); endif - b = sqrt (a.w.^2 + a.x.^2 + a.y.^2 + a.z.^2); + b = sqrt (norm2 (a)); endfunction \ No newline at end of file Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/columns.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/columns.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/columns.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,3 +1,26 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## 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 +## (at your option) 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 -*- +## Return number of columns of quaternion arrays. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: May 2010 +## Version: 0.1 + + function c = columns (a) if (nargin != 1) Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/inv.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/inv.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/inv.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,4 +1,4 @@ -## Copyright (C) 2010 Lukas F. Reichlin +## Copyright (C) 2010, 2011 Lukas F. Reichlin ## ## 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 @@ -20,7 +20,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: May 2010 -## Version: 0.1 +## Version: 0.2 function a = inv (a) @@ -35,7 +35,7 @@ ## TODO: quaternion arrays - norm2 = a.w*a.w + a.x*a.x + a.y*a.y + a.z*a.z; + norm2 = norm2 (a); a.w = a.w / norm2; a.x = -a.x / norm2; Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/mpower.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/mpower.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/mpower.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,3 +1,26 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## 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 +## (at your option) 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 -*- +## matrix power operator of quaternions. Used by Octave for "q^x". + +## Author: Lukas Reichlin <luk...@gm...> +## Created: May 2010 +## Version: 0.1 + + function a = mpower (a, b) if (b == -1 && isa (a, "quaternion") && isscalar (a.w)) Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/power.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/power.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/power.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,12 +1,38 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## 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 +## (at your option) 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 -*- +## power operator of quaternions. Used by Octave for "q.^x". + +## Author: Lukas Reichlin <luk...@gm...> +## Created: May 2010 +## Version: 0.1 + + function a = power (a, b) - if (b == -1 && isa (a, "quaternion") && isscalar (a.w)) - a = inv (a); + if (b == -1 && isa (a, "quaternion")) + norm2 = norm2 (a); + a.w = a.w ./ norm2; + a.x = -a.x ./ norm2; + a.y = -a.y ./ norm2; + a.z = -a.z ./ norm2; else error ("quaternion: power: case not implemeted"); endif - ## TODO: - q1 .^ q2 - ## - arrays + ## TODO: q1 .^ q2 endfunction \ No newline at end of file Added: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/private/norm2.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/private/norm2.m (rev 0) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/private/norm2.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -0,0 +1,30 @@ +## Copyright (C) 2011 Lukas F. Reichlin +## +## 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 +## (at your option) 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} {@var{norm2} =} norm2 (@var{q}) +## Return squared norm of a quaternion. +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: November 2011 +## Version: 0.1 + + +function ret = norm2 (a) + + ret = a.w.^2 + a.x.^2 + a.y.^2 + a.z.^2; + +endfunction \ No newline at end of file Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/rows.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/rows.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/rows.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,3 +1,26 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## 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 +## (at your option) 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 -*- +## Return number of rows of quaternion arrays. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: May 2010 +## Version: 0.1 + + function r = rows (a) if (nargin != 1) Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/size.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/size.m 2011-11-13 12:40:38 UTC (rev 9073) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/size.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -1,3 +1,26 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## 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 +## (at your option) 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 -*- +## Return size of quaternion arrays. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: May 2010 +## Version: 0.1 + + function [s, varargout] = size (a, b) switch (nargout) Added: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/unit.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/unit.m (rev 0) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/unit.m 2011-11-13 13:32:36 UTC (rev 9074) @@ -0,0 +1,39 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## 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 +## (at your option) 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} {@var{qabs} =} abs (@var{q}) +## Normalize quaternion to length 1 (unit quaternion). +## +## @example +## q = w + x*i + y*j + z*k +## unit (q) = q ./ sqrt (w.^2 + x.^2 + y.^2 + z.^2) +## @end example +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: August 2010 +## Version: 0.1 + + +function q = unit (a) + + if (nargin != 1) + print_usage (); + endif + + q = a ./ abs (a); + +endfunction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |