ribben
ribben

Reputation: 51

Quaternion 3 axis rotation

A little help here. I recieve 1 rotation per axis from a hardware gyroscope so 3 rotations for 3 axes (x,y,z) in total. When I use a matrix based rotation I get weird rotations perhaps because of the multiplication order (RotX*RotY*RotZ <> RotY*RotX*RotZ), I have also tried MatrixYawPitchRoll but the same effects appear. Thus I concluded that I should use quaternions but as fas as I can think I must create 3 quaternions, one per rotation, but when I combine them with multiplication I get the same effects as a matrix based rotation... So can someone please tell me how to properly use 3 rotations to create and combine quaternions whithout having the appearance of the previous multiplication effects?

P.S. D3DXQuaternionRotationYawPitchRoll still suffers the same effects as matrix based rotation.

Upvotes: 2

Views: 2795

Answers (2)

minorlogic
minorlogic

Reputation: 1918

I see 2 main source of problems.

  1. Your conversion from Euler Angels is broken.
  2. You use invalid Euler Angle scheme. There are exists 24 types of schemes of Euler Angels http://en.wikipedia.org/wiki/Euler_angles

Simply Euler Angle scheme is order of rotations around axis XYZ, ZYX, ZXZ ...

All conversions to/from matrix/quaternion can be found in source code to excellent article by Ken Shoemake, 1993.

http://tog.acm.org/resources/GraphicsGems/gemsiv/euler_angle/

Upvotes: 0

Nicol Bolas
Nicol Bolas

Reputation: 474236

Quaternions are not a magical salve that washes away rotational issues. All quaternions are is a cheap way to represent a specific orientation and to do orientation transforms.

Your problem is that you are not representing your orientation as a quaterion; you're representing it as a 3 angles. And it is that representation that causes your rotation problems.

You need to stop using angles. Represent an object's orientation as a quaternion. If you want to adjust your orientation, create a quaternion from your adjustment angle/axis, then multiply that into the object's orientation. Re-normalize the quaternion and you're done.

Upvotes: 3

Related Questions