Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!i76g2000hsf.googlegroups.com!not-for-mail
From: Sandro <sandro2109@aol.com>
Newsgroups: comp.soft-sys.matlab
Subject: Minimal rotation angle...
Date: Sun, 26 Oct 2008 16:37:14 -0700 (PDT)
Organization: http://groups.google.com
Lines: 50
Message-ID: <9fa07a19-86f8-4b95-b717-8e1294ff7349@i76g2000hsf.googlegroups.com>
NNTP-Posting-Host: 78.54.38.182
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1225064235 11905 127.0.0.1 (26 Oct 2008 23:37:15 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 26 Oct 2008 23:37:15 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: i76g2000hsf.googlegroups.com; posting-host=78.54.38.182; 
	posting-account=TJqYGAoAAACnuqomTdNA3xV14t43qIjV
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.1) 
	Gecko/2008070208 Firefox/3.0.1,gzip(gfe),gzip(gfe)
Bytes: 2412
Xref: news.mathworks.com comp.soft-sys.matlab:497339


Hey guys,

I am given a quaternion, which rotates three orthogonal vectors (the
coordinate system basically).

And now I have to determine the minimal angle over which to rotate the
new system to coincide with the old one

Here is how far I have come:

%convert to rotation matrix
R = quat2dcm(q);

%determine rotation axis
if (abs(det(R - eye(3))) == 0)
    [V, D] = eig(R);
    if (norm(V(:, 1)) == 1)
        v = V(:, 1);
    elseif (norm(V(:, 2)) == 1)
        v = V(:, 2);
    elseif (norm(V(:, 3)) == 1);
        v = V(:, 3);
    end
else
    v = null(R - eye(3));
end

%find another vector orthogonal to v
if (v(3) == 0) && (v(2) == 0)
    w = cross(v, [v(2) v(1) v(3)])';
else
    w = cross(v, [v(1) v(3) v(2)])';
end

ang = acos(dot(w, R*w) / (norm(w) * norm(R*w));

When testing the results I find that sometimes I have to use the
negative rotation axis to get the proper rotation. The angle seems to
fit anyway, but could anyone explain why that is?
And more importantly, when I have to go the eigenvector route, I
pretty much always get complex eigenvectors, which don't seem to go
together well with the rest of the plot. Either the rotation in the
end doesn't fit or there might also be not eigenvector of the norm
1...

How do I do it properly?

Thx a lot

Sandro