home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / la / cross.m < prev    next >
Text File  |  1999-04-29  |  1KB  |  49 lines

  1. ## Copyright (C) 1995, 1996  Kurt Hornik
  2. ## 
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this file.  If not, write to the Free Software Foundation,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  cross (x, y)
  18. ##
  19. ## Computes the vector cross product of the two 3-dimensional vectors
  20. ## x and y.
  21.  
  22. ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
  23. ## Created: 15 October 1994
  24. ## Adapted-By: jwe
  25.  
  26. function z = cross (x, y)
  27.   
  28.   if (nargin != 2)
  29.     usage ("cross (x, y)");
  30.   endif
  31.  
  32.   if (length (x) == 3 && length (y) == 3)
  33.  
  34.     z = [x(2)*y(3) - x(3)*y(2); x(3)*y(1) - x(1)*y(3); x(1)*y(2) - x(2)*y(1)];
  35.  
  36.     x_nr = rows (x);
  37.     y_nr = rows (y);
  38.  
  39.     if ((x_nr == y_nr && x_nr == 1)
  40.      || (x_nr != y_nr && ! prefer_column_vectors))
  41.       z = z.';
  42.     endif
  43.  
  44.   else
  45.     error ("cross: both x and y must be 3-dimensional vectors");
  46.   endif
  47.  
  48. endfunction
  49.