-
Notifications
You must be signed in to change notification settings - Fork 2
/
quat_prod.m
executable file
·44 lines (34 loc) · 908 Bytes
/
quat_prod.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
function res = quat_prod(p,q)
if (size(p,3) == 4)
pr=p(:,:,1);
pi=p(:,:,2);
pj=p(:,:,3);
pk=p(:,:,4);
qr=q(:,:,1);
qi=q(:,:,2);
qj=q(:,:,3);
qk=q(:,:,4);
res_r=pr.*qr-pi.*qi-pj.*qj-pk.*qk;
res_i=pr.*qi+pi.*qr+pj.*qk-pk.*qj;
res_j=pr.*qj-pi.*qk+pj.*qr+pk.*qi;
res_k=pr.*qk+pi.*qj-pj.*qi+pk.*qr;
res=cat(3,res_r,res_i,res_j,res_k);
else
pr=p(1:4:end,:);
pi=p(2:4:end,:);
pj=p(3:4:end,:);
pk=p(4:4:end,:);
qr=q(1:4:end,:);
qi=q(2:4:end,:);
qj=q(3:4:end,:);
qk=q(4:4:end,:);
res_r=pr.*qr-pi.*qi-pj.*qj-pk.*qk;
res_i=pr.*qi+pi.*qr+pj.*qk-pk.*qj;
res_j=pr.*qj-pi.*qk+pj.*qr+pk.*qi;
res_k=pr.*qk+pi.*qj-pj.*qi+pk.*qr;
res = zeros(size(p,1),size(p,2));
res(1:4:end,:) = res_r;
res(2:4:end,:) = res_i;
res(3:4:end,:) = res_j;
res(4:4:end,:) = res_k;
end