1 function cross = veccross(vec1,vec2)
3 % VECCROSS: The cross product of two vectors.
7 % cross = veccross(vec1,vec2);
11 % vec1 : An array of column vectors represented by a matrix of
12 % vec2 size (dim,nv), where is the dimension of the vector and
13 % nv the number of vectors.
17 % cross : Array of column vectors, each element is corresponding
18 % to the cross product of the respective components in vec1
23 % Cross product of two vectors.
27 % Determine the cross products of:
28 % (2.3,3.4,5.6) and (1.2,4.5,1.2)
29 % (5.1,0.0,2.3) and (2.5,3.2,4.0)
31 % cross = veccross([2.3 5.1; 3.4 0.0; 5.6 2.3],[1.2 2.5; 4.5 3.2; 1.2 4.0]);
33 % Copyright (C) 2000 Mark Spink
35 % This program is free software: you can redistribute it and/or modify
36 % it under the terms of the GNU General Public License as published by
37 % the Free Software Foundation, either version 2 of the License, or
38 % (at your option) any later version.
40 % This program is distributed in the hope that it will be useful,
41 % but WITHOUT ANY WARRANTY; without even the implied warranty of
42 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 % GNU General Public License for more details.
45 % You should have received a copy of the GNU General Public License
46 % along with this program. If not, see <http://www.gnu.org/licenses/>.
50 cross = zeros(size(vec1));
51 cross(3,:) = vec1(1,:).*vec2(2,:)-vec1(2,:).*vec2(1,:);
54 cross = [vec1(2,:).*vec2(3,:)-vec1(3,:).*vec2(2,:);
55 vec1(3,:).*vec2(1,:)-vec1(1,:).*vec2(3,:);
56 vec1(1,:).*vec2(2,:)-vec1(2,:).*vec2(1,:)];