-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRF_av_plus.m
More file actions
45 lines (38 loc) · 1.11 KB
/
RF_av_plus.m
File metadata and controls
45 lines (38 loc) · 1.11 KB
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
function [ avRF ] = RF_av_plus( RF )
%A function to average multiple Rodrigues Frank orientations. Uses quatrenion
%averaging, see below.
%RF is a concatenated n by 3 array of RF vectors.
%HISTORY:
%Modified from RF_av 20/03/19.
Q = zeros(numel(RF(:,1)), 4);
for a = 1:numel(RF(:,1))
rot = RF_to_Rot(RF(a,:));
Q(a,:) = rotm2quat(rot);
%crash
end
avQ = avg_quaternion_markley(Q);
avrot = quat2rotm(avQ');
avRF = Rot_to_AngAx(avrot, 1);
end
function [Qavg]=avg_quaternion_markley(Q)
% by Tolga Birdal
% Q is an Mx4 matrix of quaternions. Qavg is the average quaternion
% Based on
% Markley, F. Landis, Yang Cheng, John Lucas Crassidis, and Yaakov Oshman.
% "Averaging quaternions." Journal of Guidance, Control, and Dynamics 30,
% no. 4 (2007): 1193-1197.
% Form the symmetric accumulator matrix
A = zeros(4,4);
M = size(Q,1);
for i=1:M
q = Q(i,:)';
if(q(1)<0) % handle the antipodal configuration
q = -q;
end
A = q*q'+A; % rank 1 update
end
% scale
A=(1.0/M)*A;
% Get the eigenvector corresponding to largest eigen value
[Qavg, Eval] = eigs(A,1);
end