Ask Your Question
0

How do I get the angle in radians (0 to 2pi) from a quaternion?

asked 2012-08-14 07:55:17 -0500

Clefairy gravatar image

I'm trying to get the angle of a position model in Stage in radians from the Odometry message published to the "odom" topic.

This is how I've done it:

theta = 2 * asin(msg.pose.pose.orientation.z);

This sort of works in getting the angle in radians, but whenever the angle is below the x axis it gives me a negative angle.

Is there anyway of getting the angle in radians going from 0 to 2pi, starting from the positive x axis going anti-clockwise?

Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-08-14 08:13:43 -0500

dornhege gravatar image

Look in the angles package. There is a header with functions that normalize the radian. I think there is also one for [0, 2 Pi).

For getting yaw of a quaternion, there should be a function in tf that does this for you.

edit flag offensive delete link more

Comments

3
Eric Perko gravatar imageEric Perko ( 2012-08-14 08:30:11 -0500 )edit
0

answered 2018-11-22 12:21:51 -0500

A formula that give an angle from 0 to 2pi is:

f(x,y)=pi()-pi()/2(1+sign(x)) (1-sign(y^2))-pi()/4(2+sign(x))sign(y)

      -sign(x*y)*atan((abs(x)-abs(y))/(abs(x)+abs(y)))

There is x=x2-x1 and y=y2-y1,and the formula is working

for any value of x and y.For x=y=0 the result is undefined.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-08-14 07:55:17 -0500

Seen: 1,767 times

Last updated: Aug 14 '12