## Copyright (C) 1995-2012 Kurt Hornik ## ## This file is part of Octave. ## ## Octave 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. ## ## Octave 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 Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {} fastcross (@var{x}, @var{y}) ## @deftypefnx {Function File} {} cross (@var{x}, @var{y}, @var{dim}) ## Fast compute the vector cross product of two 3-vectors ONLY ## @var{x} : size 1 x 3 and @var{y} : size 1 x 3 ## ## @example ## @group ## fastcross ([1,1,0], [0,1,1]) ## @result{} [ 1; -1; 1 ] ## @end group ## @end example ## ## Simplified cross product assuming @var{x} and @var{y} are 3-vectors, ## the cross product is applied along the 3-vectors as given. ## @seealso{dot, curl, divergence} ## @end deftypefn ## Author: Kurt Hornik ## Created: 15 October 1994 ## Adapted-By: jwe ## Modified by DRE 2013 function z = fastcross (x, y) %% ONE safety if (find (size (x) == 3, 1)== 2 && find (size (y) == 3, 1)) %% ONE STEP cross product z = cat (2, (x(1,2)*y(1,3) - x(1,3)*y(1,2)), (x(1,3)*y(1,1) - x(1,1)*y(1,3)), \ (x(1,1)*y(1,2) - x(1,2)*y(1,1))); else error ("fastcross: x and y must have 1 x 3 elements"); endif endfunction