2018-07-23 08:17:51 +00:00
|
|
|
function so3mat = MatrixLog3(R)
|
2018-07-23 21:47:50 +00:00
|
|
|
% *** CHAPTER 3: RIGID-BODY MOTIONS ***
|
2018-07-23 08:17:51 +00:00
|
|
|
% Takes R (rotation matrix).
|
|
|
|
|
% Returns the corresponding so(3) representation of exponential
|
|
|
|
|
% coordinates.
|
|
|
|
|
% Example Input:
|
2018-07-23 21:47:50 +00:00
|
|
|
%
|
|
|
|
|
% clear; clc;
|
|
|
|
|
% R = [[0, 0, 1]; [1, 0, 0]; [0, 1, 0]];
|
|
|
|
|
% so3mat = MatrixLog3(R)
|
|
|
|
|
%
|
2018-07-23 08:17:51 +00:00
|
|
|
% Output:
|
|
|
|
|
% angvmat =
|
|
|
|
|
% 0 -1.2092 1.2092
|
|
|
|
|
% 1.2092 0 -1.2092
|
|
|
|
|
% -1.2092 1.2092 0
|
|
|
|
|
|
2018-12-24 08:05:24 +00:00
|
|
|
acosinput = (trace(R) - 1) / 2;
|
|
|
|
|
if acosinput >= 1
|
|
|
|
|
so3mat = zeros(3);
|
|
|
|
|
elseif acosinput <= -1
|
2018-07-23 08:17:51 +00:00
|
|
|
if ~NearZero(1 + R(3, 3))
|
2018-12-24 08:05:24 +00:00
|
|
|
omg = (1 / sqrt(2 * (1 + R(3, 3)))) ...
|
|
|
|
|
* [R(1, 3); R(2, 3); 1 + R(3, 3)];
|
2018-07-23 08:17:51 +00:00
|
|
|
elseif ~NearZero(1 + R(2, 2))
|
2018-12-24 08:05:24 +00:00
|
|
|
omg = (1 / sqrt(2 * (1 + R(2, 2)))) ...
|
|
|
|
|
* [R(1, 2); 1 + R(2, 2); R(3, 2)];
|
2018-07-23 08:17:51 +00:00
|
|
|
else
|
2018-12-24 08:05:24 +00:00
|
|
|
omg = (1 / sqrt(2 * (1 + R(1, 1)))) ...
|
|
|
|
|
* [1 + R(1, 1); R(2, 1); R(3, 1)];
|
2018-07-23 08:17:51 +00:00
|
|
|
end
|
|
|
|
|
so3mat = VecToso3(pi * omg);
|
|
|
|
|
else
|
2018-12-24 08:05:24 +00:00
|
|
|
theta = acos(acosinput);
|
2018-07-23 08:17:51 +00:00
|
|
|
so3mat = theta * (1 / (2 * sin(theta))) * (R - R');
|
|
|
|
|
end
|
|
|
|
|
end
|