-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrp2aa.m
37 lines (29 loc) · 817 Bytes
/
grp2aa.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 [theta, r] = grp2aa(p, a, f)
% grp2aa
% Copyright 2016 An Uncommon Lab
%#codegen
% Set defaults so that p approximates the rotation vector for small
% angles.
if nargin < 2 || isempty(a), a = 1; end;
if nargin < 3 || isempty(f), f = 2*(a+1); end;
% Get the magnitude and rotation axes.
if nargout >= 2
[r, pm] = normalize(p);
else
pm = vmag(p);
end
% Remove the scaling factor.
if f ~= 1
pm = pm ./ f;
end
% The angle is easy when a == 1. There's a bit more footwork
% when a ~= 1.
if a == 1
theta = 4 * atan(pm);
else
pm = pm .* pm;
theta = -a * pm + sqrt(1 + (1-a*a) * pm);
theta = theta ./ (1 + pm);
theta = 2 * acos(theta);
end
end % grp2aa