]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/veccross.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / veccross.m
1 function cross = veccross(vec1,vec2)
2
3 % VECCROSS: The cross product of two vectors.
4
5 % Calling Sequence:
6
7 %   cross = veccross(vec1,vec2);
8
9 % INPUT:
10
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.
14 %
15 % OUTPUT:
16
17 %   cross       : Array of column vectors, each element is corresponding
18 %               to the cross product of the respective components in vec1
19 %               and vec2.
20
21 % Description:
22
23 %   Cross product of two vectors.
24
25 % Examples:
26
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)
30
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]);
32 %
33 %    Copyright (C) 2000 Mark Spink
34 %
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.
39
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.
44 %
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/>.
47
48 if size(vec1,1) == 2
49   % 2D vector
50   cross = zeros(size(vec1));
51   cross(3,:) = vec1(1,:).*vec2(2,:)-vec1(2,:).*vec2(1,:);
52 else
53   % 3D vector
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,:)];
57 end
58
59 end