Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: angle from rotation matrix
Date: Mon, 17 Dec 2007 18:19:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 59
Message-ID: <fk6eis$ra6$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>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
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 1197915548 27974 172.30.248.35 (17 Dec 2007 18:19:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 Dec 2007 18:19:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:442809


James Tursa <aclassyguywithaknotac@hotmail.com> wrote in message 
<2shcm3pkforks50k3jjkjo0bdkioir9jq2@4ax.com>...
> For the particular case of theta near pi (and for cases near 0 ........
-------
Hello James,

Your example with three successive rotations, each near pi, ends up with a 
net rotation through a very small angle, theta = 1.7903e-014, and your A is 
close to the identity matrix.  In fact, if you do the three successive rotations 
with 'ang' exactly equal to pi, you get precisely the identity transformation, as 
one can see on paper and pencil.  This is not the case I was worried about!  It 
is when the value of theta for the final transformation turns out to be near pi 
that there will be accuracy problems.

  I have run an example to demonstrate this.  The general expression for a 
rotation matrix A about the rotation axis with unit vector v = [p;q;r] and 
rotation angle w is:

 A = [...
 p^2+cos(w)*(q^2+r^2),(1-cos(w))*p*q-sin(w)*r,(1-cos(w))*r*p+sin(w)*q;
 (1-cos(w))*p*q+sin(w)*r,q^2+cos(w)*(r^2+p^2),(1-cos(w))*q*r-sin(w)*p;
 (1-cos(w))*r*p-sin(w)*q,(1-cos(w))*q*r+sin(w)*p,r^2+cos(w)*(p^2+q^2)];

If we choose the following values for w and v:

 w = pi-(1e-14);
 v = [1.1;1.2;1.3]; v = v/norm(v);
 p = v(1); q = v(2); r = v(3);

this gives:

 A =
  -0.44239631336406   0.60829493087557   0.65898617511521
   0.60829493087558  -0.33640552995392   0.71889400921658
   0.65898617511520   0.71889400921660  -0.22119815668203

As you can see, when diagonally opposite elements of A are subtracted, we 
have the much-feared subtraction-of-large-quantities-with-small-
differences situation that can produce very large relative round-off errors.

  Specifically, Bruno's second method yields:

 u =
   0.52590972519131
   0.57957398286389
   0.62250538900196

which is markedly different from the original value, v, along the true axis of 
rotation:

 v =
   0.52801689681105
   0.57601843288478
   0.62401996895852

The components of u are off from those in v in the third decimal place, which 
can hardly be considered robust computation.

Roger Stafford