Ask Your Question

TF quaternion rotation problem

asked 2017-11-30 18:05:13 -0600

jlin gravatar image

updated 2017-12-01 15:49:18 -0600

jayess gravatar image

My goal is to rotate a quaternion by a yaw angle. q1 is the quaternion that I want to rotate

q1 = quaternion_from_euler(math.pi/2, math.pi/4, math.pi/4)

I want to rotate q1 by 1/4 pi yaw so I create another quaternion q2 for the purpose

q2 = quaternion_from_euler(0, 0, math.pi/4)

I then rotate q1 and I expect the result to be (pi/2, pi/4, pi/2) roll-pitch-yaw

q3 = quaternion_multiply(q1, q2)

But when I convert the result to Euler below is the value.

e3 = euler_from_quaternion(q3)
print e3
(1.5707963267948966, -0.0, 0.7853981633974484)

Looks like it rotates pitch by -pi/4 instead of the yaw by pi/4. Am I doing something wrong? Thanks for any help.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-12-01 02:26:20 -0600

AndyZe gravatar image

Try q3 = quaternion_multiply(q2, q1). Order matters.

edit flag offensive delete link more


Thanks. That works.

jlin gravatar imagejlin ( 2017-12-01 16:45:36 -0600 )edit

answered 2017-12-01 22:43:26 -0600

updated 2017-12-03 23:12:43 -0600

To expand on Andy's answer, the order determines whether you're applying a global or local rotation.

q3 = quaternion_multiply(q1, q2)

Here q3 is the local rotation of q2 on q1
the global rotation of q1 on q2

q3 = quaternion_multiply(q2, q1)

Here q3 is the local rotation of q1 on q2
the global rotation of q2 on q1

In your case, you wanted to apply a global rotation of q2 on q1 -
i.e. apply the rotation q2 according to q1's parent coordinate frame (the coordinate frame on which q1 was applied initially)

Further reading / maths:

edit flag offensive delete link more


Thanks! That really helps.

jlin gravatar imagejlin ( 2017-12-01 22:46:25 -0600 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2017-11-30 18:05:13 -0600

Seen: 187 times

Last updated: Dec 03 '17