Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <brunoluong@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: angle from rotation matrix
Date: Sat, 15 Dec 2007 12:54:33 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 39
Message-ID: <fk0iq9$k0j$1@fred.mathworks.com>
References: <fjvbqk$gbt$1@fred.mathworks.com> <fk0cpd$g0v$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <brunoluong@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197723273 20499 172.30.248.35 (15 Dec 2007 12:54:33 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 15 Dec 2007 12:54:33 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1184112
Xref: news.mathworks.com comp.soft-sys.matlab:442588


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fk0cpd$g0v$1@fred.mathworks.com>...

>   The following then is the needed matlab computation:
> 
>  [V,D] = eig(A);
>  [ignore,ix] = min(abs(diag(D)-1));
>  w = V(:,ix);
>  t = [A(3,2)-A(2,3),A(1,3)-A(3,1),A(2,1)-A(1,2)];
>  theta = atan2(t*w,trace(A)-1);
>  if theta<0, theta = -theta; w = -w; end
> 

One can use either eig() or direct calculation from A:

%%%% First method 

D=eig(A);
[dummy k]=max(abs(D-1));
theta=angle(D(k))


%%%%% Second method, returned angle in [0,pi]

c=(trace(A)-1);
s=norm([A(3,2)-A(2,3);...
        A(1,3)-A(3,1); ...
        A(2,1)-A(1,2)]);
theta=atan2(s,c) % better than using acos or asin

%%%%%%%%%%

Of course, the sign of theta is arbitrary chosen. It must be
compatible with the +/- direction of the rotation vector as
Roger pointed out.

Bruno