-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_omega.m
87 lines (72 loc) · 1.91 KB
/
get_omega.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
function omega = get_omega(o1,o2)
arguments
o1 (:,8) double {mustBeReal,mustBeFinite}
o2 (:,8) double {mustBeReal,mustBeFinite}
end
% GET_OMEGA calculate octonion distance
%--------------------------------------------------------------------------
% Author: Sterling Baird
%
% Date:
%
% Description:
%
% Inputs: o1, o2 form an octonion pair, each can be rows of octonions
%
% Outputs:
%
% Dependencies:
%
%--------------------------------------------------------------------------
% enables use as custom distance function to e.g. pdist2
if size(o1,1) == 1
npts = size(o2,1);
o1 = repmat(o1,npts,1);
end
if size(o2,1) == 1
npts = size(o1,1);
o2 = repmat(o2,npts,1);
end
qA = normr(o1(:,1:4));
qB = normr(o1(:,5:8));
qC = normr(o2(:,1:4));
qD = normr(o2(:,5:8));
dot1 = dot(qA,qC,2);
dot2 = dot(qB,qD,2);
omega = real(2*acos(abs(dot1+dot2)/2)); %added real() 2020-08-03
end
%----------------------------END get_omega()-------------------------------
% %--------------------------VALIDATION FUNCTIONS----------------------------
% % Custom validation function
% function normMustBeSqrt2(val)
%
% tol = 0.1;
% normcheck = abs(norm(val(1,:))-sqrt(2)) < tol;
% errmsg = ['octonion norm must be equal to sqrt(2) within tol = ' num2str(tol)];
% assert(normcheck,errmsg)
%
% end
% function quatNormsMustBeOne(val)
%
% tol = 0.1;
% qAcheck = abs(norm(val(1,1:4))-1) < tol;
% qBcheck = abs(norm(val(1,5:8))-1) < tol;
% errmsg = ['quaternion norms must be equal to 1 within tol = ' num2str(tol)];
% assert(qAcheck && qBcheck,errmsg)
%
% end
%----------------------------CODE GRAVEYARD--------------------------------
%{
% adjust values that are close to 1 or -1
tol = 1e-6;
dot1(abs(dot1 - 1) < tol) = 1;
dot2(abs(dot2 - 1) < tol) = 1;
dot1(dot1 > 1) = 1;
dot2(dot2 > 1) = 1;
dot1(dot1 < -1) = -1;
dot2(dot2 < -1) = -1;
dot1(abs(dot1 + 1) < tol) = -1;
dot2(abs(dot2 + 1) < tol) = -1;
,normMustBeSqrt2(o1)
,normMustBeSqrt2(o2)
%}