tp@0
|
1 function distances = EDB1calcdist(x1,x2)
|
tp@0
|
2 % EDB1calcdist - Gives distances between sets of points in 3D space.
|
tp@0
|
3 % EDB1calcdist returns a matrix of distances from all n1 points
|
tp@0
|
4 % in x1 to all n2 points in x2.
|
tp@0
|
5 %
|
tp@0
|
6 % Input parameters:
|
tp@0
|
7 % x1 Matrix, [n1,3], with the coordinates of n1 points.
|
tp@0
|
8 % x2 Matrix, [n2,3], with the coordinates of n2 points.
|
tp@0
|
9 %
|
tp@0
|
10 % Output parameters:
|
tp@0
|
11 % distances Matrix, [n1,n2], with the distances from all
|
tp@0
|
12 % points in x1 to all points in x2.
|
tp@0
|
13 %
|
tp@0
|
14 % Uses no special functions.
|
tp@0
|
15 %
|
tp@0
|
16 % ----------------------------------------------------------------------------------------------
|
tp@0
|
17 % This file is part of the Edge Diffraction Toolbox by Peter Svensson.
|
tp@0
|
18 %
|
tp@0
|
19 % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify
|
tp@0
|
20 % it under the terms of the GNU General Public License as published by the Free Software
|
tp@0
|
21 % Foundation, either version 3 of the License, or (at your option) any later version.
|
tp@0
|
22 %
|
tp@0
|
23 % The Edge Diffraction Toolbox is distributed in the hope that it will be useful,
|
tp@0
|
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
tp@0
|
25 % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
tp@0
|
26 %
|
tp@0
|
27 % You should have received a copy of the GNU General Public License along with the
|
tp@0
|
28 % Edge Diffraction Toolbox. If not, see <http://www.gnu.org/licenses/>.
|
tp@0
|
29 % ----------------------------------------------------------------------------------------------
|
tp@0
|
30 % Peter Svensson (svensson@iet.ntnu.no) 20001010
|
tp@0
|
31 %
|
tp@0
|
32 % distances = EDB1calcdist(x1,x2);
|
tp@0
|
33
|
tp@0
|
34 [n11,n12] = size(x1);
|
tp@0
|
35 [n21,n22] = size(x2);
|
tp@0
|
36
|
tp@0
|
37 if n12 ~= 3 | n22 ~= 3
|
tp@0
|
38 disp('Coordinates must be specified as [x y z]')
|
tp@0
|
39 else
|
tp@0
|
40 if n11 == 1
|
tp@0
|
41 x1 = x1(ones(n21,1),:);
|
tp@0
|
42 d1 = x1-x2;
|
tp@0
|
43 distances = sqrt(sum( (d1.').^2 ));
|
tp@0
|
44 elseif n21 == 1
|
tp@0
|
45 x2 = x2(ones(n11,1),:);
|
tp@0
|
46 d1 = x1-x2;
|
tp@0
|
47 distances = sqrt(sum( (d1.').^2 )).';
|
tp@0
|
48 else
|
tp@0
|
49 distances = zeros(n11,n21);
|
tp@0
|
50 for ii = 1:n21
|
tp@0
|
51 x2point = x2(ii,:);
|
tp@0
|
52 x2point = x2point(ones(n11,1),:);
|
tp@0
|
53 d1 = x1 - x2point;
|
tp@0
|
54 distances(:,ii) = sqrt(sum( (d1.').^2 )).';
|
tp@0
|
55 end
|
tp@0
|
56 end
|
tp@0
|
57 end
|
tp@0
|
58
|