Ask Your Question
0

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

asked 2018-09-10 08:31:33 -0600

smihael gravatar image

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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by allenh1
close date 2018-09-13 11:14:45.625950

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-09-10 09:09:12 -0600

updated 2018-09-11 05:07:17 -0600

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 x arccos(w))

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.

edit flag offensive delete link more

Comments

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

smihael gravatar imagesmihael ( 2018-09-11 03:14:10 -0600 )edit

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.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-09-11 05:00:46 -0600 )edit

Ok thanks, I thought that the Wikipedia was maybe better because essentially it enforces normalization on the vector part or something into this direction.

smihael gravatar imagesmihael ( 2018-09-11 06:33:13 -0600 )edit

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

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-09-11 06:37:00 -0600 )edit
0

answered 2018-09-10 10:06:43 -0600

Thomas D gravatar image

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.

edit flag offensive delete link more

Comments

I think an example would be appreciated by future searchers

fvd gravatar imagefvd ( 2018-09-10 19:50:30 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 244 times

Last updated: Sep 11 '18