[Index for tmp_for_tar/misc]
[Return to Master Index]
cross
(tmp_for_tar/misc/cross.m)
Function Synopsis
z = cross (x, y)
Help text
z = cross (x, y)
Computes the vector cross product of two 3-dimensional vectors.
x and y may be Px3 (default) or 3xP. If x and y have same size, the
result has same size as the arguments. If one argument is Px3 and the
other 3xP, the size of the result will be Px3 unless if
prefer_column_vectors is set.
Created: 15 October 1994
Adapted-By: jwe
Further modified by etienne@isr.ist.utl.pt (1999).
Listing of function file tmp_for_tar/misc/cross.m
## z = cross (x, y)
##
## Computes the vector cross product of two 3-dimensional vectors.
##
## x and y may be Px3 (default) or 3xP. If x and y have same size, the
## result has same size as the arguments. If one argument is Px3 and the
## other 3xP, the size of the result will be Px3 unless if
## prefer_column_vectors is set.
## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
## Created: 15 October 1994
## Adapted-By: jwe
## Further modified by etienne@isr.ist.utl.pt (1999).
##
## Copyright (C) 1995, 1996 Kurt Hornik
##
## 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 2, 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 file. If not, write to the Free Software Foundation,
## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
function z = cross (x, y)
if (nargin != 2)
usage ("cross (x, y)");
endif
# Don't fuss about row/column size
ntog = 0 ; # Number of toggled arguments
if size(x,2) != 3 && size(x,1) == 3,
x = x.' ;
ntog++;
end
if size(y,2) != 3 && size(y,1) == 3,
y = y.' ;
ntog++;
end
if (size (x,2) == 3 && size (y,2) == 3)
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)];
## Return column only if both args were columns, or one arg was
## column and prefer_column_vectors is set.
if ntog == 2 || ( (ntog == 1) && ! prefer_column_vectors)
z = z.';
endif
else
error ("cross: both x and y must be 3-dimensional vectors");
endif
endfunction
Produced by oct2html on Sat Apr 28 21:14:54 2001
Cross-Directory links are: ON