-
Notifications
You must be signed in to change notification settings - Fork 2
/
sqrt2norm.m
70 lines (65 loc) · 1.87 KB
/
sqrt2norm.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
function pts = sqrt2norm(pts,type,nv)
arguments
pts double {mustBeNumeric,mustBeFinite}
type char {mustBeMember(type,{'oct','quat'})} = 'oct'
nv.warnQ(1,1) logical = true
end
% sqrt2norm take a set of octonions and give each row norm == sqrt(2) if (norm == 1) || (norm == sqrt(2))
%--------------------------------------------------------------------------
% Author: Sterling Baird
%
% Date: 2020-07-27
%
% Description: a
%
% Inputs:
% a - a
%
% Outputs:
% b - b
%
% Usage:
% a = b(a);
%
% Dependencies:
% *
%
% Notes:
% *
%--------------------------------------------------------------------------
tol = 1e-2;
warnQ = nv.warnQ;
switch type
case 'quat'
% if norm(o) == 1 within tolerance, multiply by sqrt(2)
if all(abs(vecnorm(pts(:,1:4),2,2)-1/sqrt(2)) < tol) ...
&& ...
all(abs(vecnorm(pts(:,5:8),2,2)-1/sqrt(2)) < tol)
%fine, no warning
elseif all(abs(vecnorm(pts(:,1:4),2,2)-1) >= tol) ...
|| ...
all(abs(vecnorm(pts(:,5:8),2,2)-1) >= tol)
if warnQ
warning(['norm(qA) == ' num2str(norm(pts(1,1:4))) ', ' ...
'norm(qB) == ' num2str(norm(pts(1,5:8))) ...
'. norm of 1+ quaternions ~= 0.7071 || 1'])
end
end
pts(:,1:4) = normr(pts(:,1:4));
pts(:,5:8) = normr(pts(:,5:8));
case 'oct'
ptnm = vecnorm(pts,2,2);
if ~isempty(find(ptnm == 0, 1))
% warning('identity octonion(s) present')
ptnm(ptnm == 0) = [];
end
if all(abs(ptnm - 1) < tol)
%fine, no warning
elseif any(abs(ptnm - sqrt(2)) >= tol)
if warnQ
warning('norm of octonions ~= 1 || sqrt(2)')
end
end
pts = normr(pts)*sqrt(2);
end
end