Mercurial > forge
changeset 8890:66afab2769ed octave-forge
quaternion-oo: convert to octave style
author | paramaniac |
---|---|
date | Sun, 13 Nov 2011 13:54:47 +0000 |
parents | c26bca43644b |
children | f82abded74a1 |
files | extra/quaternion_oo/devel/q2rot.m extra/quaternion_oo/devel/rot2q.m |
diffstat | 2 files changed, 24 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/quaternion_oo/devel/q2rot.m Sun Nov 13 13:43:25 2011 +0000 +++ b/extra/quaternion_oo/devel/q2rot.m Sun Nov 13 13:54:47 2011 +0000 @@ -1,13 +1,13 @@ function [vv, theta] = q2rot (q) - if (nargin ~= 1 || nargout ~= 2) + if (nargin != 1 || nargout != 2) print_usage (); - end + endif if (abs (norm (q) - 1) > 1e-12) - warning ('quaternion: ||q||=%e, setting=1 for vv, theta', norm (q)); - q = q / norm (q); - end + warning ("quaternion: ||q||=%e, setting=1 for vv, theta", norm (q)); + q = unit (q); + endif s = q.s; x = q.x; @@ -18,14 +18,14 @@ if (abs (theta) > pi) theta = theta - sign (theta) * pi; - end + endif sin_th_2 = norm ([x, y, z]); - if (sin_th_2 ~= 0) + if (sin_th_2 != 0) vv = [x, y, z] / sin_th_2; else vv = [x, y, z]; - end + endif -end \ No newline at end of file +endfunction \ No newline at end of file
--- a/extra/quaternion_oo/devel/rot2q.m Sun Nov 13 13:43:25 2011 +0000 +++ b/extra/quaternion_oo/devel/rot2q.m Sun Nov 13 13:54:47 2011 +0000 @@ -1,33 +1,33 @@ function q = rot2q (vv, theta) - if (nargin ~= 2 || nargout ~= 1) + if (nargin != 2 || nargout != 1) print_usage (); - end + endif - if (~ isvector (vv) || length (vv) ~= 3) - error ('vv must be a length three vector'); - end + if (! isvector (vv) || length (vv) != 3) + error ("vv must be a length three vector"); + endif - if (~ isscalar (theta)) - error ('theta must be a scalar'); - end + if (! isscalar (theta)) + error ("theta must be a scalar"); + endif if (norm (vv) == 0) - error ('quaternion: vv is zero'); - end + error ("quaternion: vv is zero"); + endif if (abs (norm (vv) - 1) > 1e-12) - warning ('quaternion: ||vv|| != 1, normalizing') + warning ("quaternion: ||vv|| != 1, normalizing") vv = vv / norm (vv); - end + endif if (abs (theta) > 2*pi) - warning ('quaternion: |theta| > 2 pi, normalizing') + warning ("quaternion: |theta| > 2 pi, normalizing") theta = rem (theta, 2*pi); - end + endif vv = vv * sin (theta / 2); d = cos (theta / 2); q = quaternion (d, vv(1), vv(2), vv(3)); -end \ No newline at end of file +endfunction \ No newline at end of file