This forum has been archived. All content is frozen. Please use KDE Discuss instead.

AngleAxisr weirdness?

Tags: None
(comma "," separated)
eudoxos
Registered Member
Posts
36
Karma
0

AngleAxisr weirdness?

Tue Apr 16, 2013 8:53 pm
I have a quaternion which, when converted to AxisAngle, yields angle which is (almost) 2*pi. I am a bit surprised, since most the time quaternions did just the right thing in representing the rotation in a very intuitive way - e.g. nearly +2*pi rotation would be represented as a very small positive rotation around the inverse axis, when converted to angle-axis (IIRC - I actually rarely have to do that conversion). What's the problem? Should I always say something like
Code: Select all
if(angle>M_PI) andle-=2*M_PI;

The documentation does not specify range for angle; the source says
Code: Select all
m_angle = Scalar(2)*acos((min)((max)(Scalar(-1),q.w()),Scalar(1)));

where std::acos (according to man acos) should give the result in range 0...pi, so the 0...2*pi range for angle is technically correct (but still surprising).

This is an example with numbers:
Code: Select all
#include<iostream>
#include<eigen3/Eigen/Geometry>
using namespace Eigen;

int main(){
   Quaterniond cr2(AngleAxisd(3.14159,Vector3d(0.382683,-0.92388,6.98402e-09)));
   Quaterniond rr2(AngleAxisd(3.14159,Vector3d(-0.382683,0.92388,0)));
   Quaterniond q=rr2*cr2.conjugate();
   AngleAxisd aa(q);
   std::cerr<<aa.angle()<<" rad around "<<aa.axis().transpose()<<std::endl;
}

which gives me
Code: Select all
6.28319 rad around   -0.385113    0.922869 -3.4935e-09


Cheers, Vaclav
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: AngleAxisr weirdness?

Fri Apr 19, 2013 7:08 am
I guess that's just a matter of taste. Now it's true that we can see this conversion as an atan2 that by convention returns values in [-pi,pi] range.
eudoxos
Registered Member
Posts
36
Karma
0

Re: AngleAxisr weirdness?

Fri Apr 19, 2013 3:23 pm
From my POV the most convenient would be to have the angle in the [0..pi] range, and inverse the axis if is the angle is <0 or >pi, to force the angle go back to [0..pi].

I agree that it is a matter of taste but I also plea for documenting the behavior, whichever it is.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]