-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathedist.m
executable file
·120 lines (95 loc) · 3.08 KB
/
edist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
% edist : Euclidean distance
%
% Call :
% D=edist(p1,p2,transform,isorange)
%
% p1,p2 : vectors
%
% transform : GSTAT anisotropy and/or range information
%
% isorange : [0] (default), transform is the usual GSTAT-anisotropy setting
% isorange : [1] means that transform simply lists the range in
% each dimensions, and that no rotation is performed
function [D,dp]=edist(p1,p2,transform,isorange)
if nargin<4
isorange=0;
end
if nargin==1;
p2=0.*p1;
end
n_dim=size(p1,2);
dp=(p2-p1);
if isorange==1
%mgstat_verbose(sprintf('%s : isorange',mfilename))
% ONLY SCCALING,edit no transformation
if length(transform)==1;
transform=ones(1,n_dim).*transform;
end
if transform==0
% Do not transfrom since this is likely a nugget
else
for j=1:n_dim;
dp(:,j)=dp(:,j)./transform(j);
end
dp=transform(1).*dp;
end
else
% 2D COORDINATE TRANSFORMATION
if (nargin>2)&(n_dim==2);
%mgstat_verbose(sprintf('%s : 2D coordinate transform'),0);
if length(transform)>1
if length(transform)==6
t=transform;
transform=zeros(1,3);
transform(1:3)=t([1,2,5]);
end
rescale=transform([1,3]);
r1=rescale(1);
r2=rescale(1)*rescale(2);
rotate=transform(2)*pi/180;
% ROTATE
RotMat=[cos(rotate) -sin(rotate);sin(rotate) cos(rotate)];
dp=(RotMat*dp')';
% SCALE
dp(:,2)=dp(:,2)./1;
dp(:,1)=dp(:,1)./rescale(2);
end
end
% 3D COORDINATE TRANSFORMATION
if (nargin>2)&(n_dim==3);
% NOT YET IMPLEMENTED, SEE GSLIB BOOK
if length(transform)>1 % length(trasnform)=1 --> isotropic
if length(transform)==3;
% 2D Anisotropy only;
t=transform;
transform=zeros(1,6);
transform([1,2,5])=t;
transform(6)=1;
end
rescale=transform([1,5,6]);
a=transform(2:4)*pi/180;
% SGEMS DEF
%T1 = [ 1 0 0 ; 0 cos(a(3)) sin(a(3)) ; 0 -sin(a(3)) cos(a(3))];
%T2 = [ sin(a(2)) 0 -cos(a(2)) ; 0 1 0 ; cos(a(2)) 0 sin(a(2))];
%T3 = [ sin(a(1)) -cos(a(1)) 0 ; cos(a(1)) sin(a(1)) 0 ; 0 0 1];
% WIKIPEDIA
T1 = [ 1 0 0 ; 0 cos(a(3)) -sin(a(3)) ; 0 sin(a(3)) cos(a(3))];
T2 = [ cos(a(2)) 0 sin(a(2)) ; 0 1 0 ; -sin(a(2)) 0 cos(a(2))];
T3 = [ cos(a(1)) -sin(a(1)) 0 ; sin(a(1)) cos(a(1)) 0 ; 0 0 1];
RotMat=T1*T2*T3;
% ROTATE
dp=(RotMat*dp')';
% SCALE
dp(:,2)=dp(:,2)./1;
dp(:,1)=dp(:,1)./rescale(2);
dp(:,3)=dp(:,3)./rescale(3);
end
end
end
if n_dim==1
D=abs(dp);
elseif n_dim==2
D=sqrt(dp(:,1).^2+dp(:,2).^2);
else
D=transpose(sqrt(sum(transpose(dp.^2))));
end