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: Mon, 17 Dec 2007 23:07:18 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <fk6vf6$9gt$1@fred.mathworks.com>
References: <fjvbqk$gbt$1@fred.mathworks.com> <fk0cpd$g0v$1@fred.mathworks.com> <fk0iq9$k0j$1@fred.mathworks.com> <fk59hv$n5r$1@fred.mathworks.com> <2shcm3pkforks50k3jjkjo0bdkioir9jq2@4ax.com> <fk6eis$ra6$1@fred.mathworks.com> <fk6ief$3kq$1@fred.mathworks.com> <fk6q3s$dns$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <brunoluong@yahoo.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197932838 9757 172.30.248.37 (17 Dec 2007 23:07:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 Dec 2007 23:07:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1184112
Xref: news.mathworks.com comp.soft-sys.matlab:442845


"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fk6q3s$dns$1@fred.mathworks.com>...
This code looks 
> for the best numerical way to combine the A elements to 
> form the quaternion.

James, I have not take a look at your code (need too revise
my quaternion lesson first, that was long ago), but could
you please elaborate (or give a hint) why it is the "best" ?

Thanks.

Bruno

PS: in the mean time, I'm trying to improve mine, still. ;-)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


c=(trace(A)-1);
u=[A(3,2)-A(2,3);...
   A(1,3)-A(3,1); ...
   A(2,1)-A(1,2)];
s=norm(u);
theta=atan2(s,c)

if c<0 % <- Use diagonal terms to estimate u
    signu=sign(u);
    signu(signu==0)=1; % we don't want the nil case
    u2=(2*diag(A)-c)/(2-c);
    u=sqrt(u2.*(u2>0)).*signu
elseif s~=0 % <- use off-diagonal terms to estimate u
    u=u/s
else
    warning('Rotation matrix close to identity');
    u=[1 0 0]
end