# tf::Quaternion getAngle() eqivalent for rospy [closed]

Is there an equivalent to the getAngle() method of C++ interface of tf in Python version too?

ROS Eloquent Elusor tshirts are available until Dec 12th. Order yours now!

tf::Quaternion getAngle() eqivalent for rospy [closed]

Is there an equivalent to the getAngle() method of C++ interface of tf in Python version too?

close date 2018-09-13 11:14:45.625950

add a comment

0

I don't know if there's a built in function to do this. But the relationship between the w element of a quaternion and the angle it's rotating by is fairly simple.

```
w = cos(angle / 2)
```

therefore:

```
angle = 2 x arccos(w)
```

So you can calculate this yourself using this equation from the w element.

**Update:**

This is mathematically equivalent to the more complex form shown on the Wikipedia page here. See their curves here:

angle = 2*atan2(sqrt(1-w^2), w),+w))

Note: I've replaced `sqrt(qi^2 + qj^2 + qk^2)`

with `sqrt(1-qr^2)`

since this expression can more easily be calculated using just the w value.

Are there any preconditions to be met to use this formula? Wikipedia uses atan2 ( https://en.wikipedia.org/wiki/Quatern... )

The two equations are mathematically equivalent, for some reason they've put the more complex form on Wikipedia! I've added the graphs of them both to my answer, as you can see they give the same results.

No worries, rotation quaternions are 4D unit vectors so they should always be normalized.

0

The tf.transformations library has a lot of useful conversion methods for rotations.

You can get Euler angles from your quaternion. If you are trying to get the axis-angle representation you could get a rotation matrix from your quaternion and convert that to axis-angle.

Asked: ** 2018-09-10 08:31:33 -0600 **

Seen: **252 times**

Last updated: **Sep 11 '18**

Difference between tf2::convert and tf2::to/fromMsg

With rospy, messages don't seem to be recieved if published soon after creating the publisher

message_filters doesn't call the callback function

urdf ImportError: No module named 're'

Connection refused - docker to docker

Velodyne VLP16 frequency too low

ROS Answers is licensed under Creative Commons Attribution 3.0 Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.