-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqmult.m
37 lines (32 loc) · 858 Bytes
/
qmult.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
function out = qmult(pp,qq,epsijk)
arguments
pp(:,4) double {mustBeReal,mustBeFinite}
qq(:,4) double {mustBeReal,mustBeFinite}
epsijk = 1
end
% epsijk = 1;
% global epsijk
% if isempty(epsijk)
% setGlobal_epsijk(1)
% end
% multiply lists of quaternion pairs (input: rows of quaternions),
% vectorized by SGB 2020-07-27
p = pp(:,2:4); q = qq(:,2:4);
qr = pp(:,1).*qq(:,1) - dot(p,q,2);
qi = pp(:,1).*q + qq(:,1).*p + epsijk*cross(p,q,2);
out = [qr qi];
% %negate quaternions if scalar part is negative
% ids = qr < 0;
% out(ids,:) = -out(ids,:);
end
%----------------------------CODE GRAVEYARD--------------------------------
%{
CMU group original function (single pair multiplication)
%%% multiply two quaternions p*q
% p = pp(2:4); q = qq(2:4);
%
% qr = pp(1)*qq(1)-dot(p,q);
% qi = pp(1)*q + qq(1)*p + cross(p,q);
%
% out = [qr qi];
%}