• Create Account

# Invert quaternion X,Z rotation

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1JackM  Members   -  Reputation: 103

Like
0Likes
Like

Posted 18 December 2013 - 06:37 AM

Hi everyone,

I have a device that returns me all four components of a quaternion (X,Y,Z,W).
The problem is that,the rotation around the X and Z axis are inverse (i rotate the device left,i get a right rotation etc)
For what i know that quaternion rapresent orientation referring to an 'arbitrary' axis so i can't just negate the rotation like i would do with euler angles as far as i know
My code is:

Quaternion rotation = new Quaternion(X,Z,Y, -W);  //i had to swap Z and Y due to the device axis orientation so i had to negate W
model.World = Matrix.CreateFromQuaternion(rotation)*Matrix.CreateTranslation(Vector3.Zero);


Any ideas on how i can invert the rotation around X and Z?

### #2Álvaro  Crossbones+   -  Reputation: 9895

Like
0Likes
Like

Posted 18 December 2013 - 09:33 AM

Where did you get X, Y, Z and W from? Can you describe the "device axis orientation" and in general your coordinate conventions in more detail?

### #3DT....  Members   -  Reputation: 487

Like
0Likes
Like

Posted 18 December 2013 - 04:00 PM

The problem is that,the rotation around the X and Z axis are inverse (i rotate the device left,i get a right rotation etc)

I think your device is using left-handed coordinates, and your code is using right-handed coordinates (or the other way around.)

Quaternion rotation = new Quaternion(X,Z,Y, -W); //i had to swap Z and Y due to the device axis orientation so i had to negate W

Try:

Quaternion rotation = new Quaternion(X, Y, -Z, W);

### #4JackM  Members   -  Reputation: 103

Like
0Likes
Like

Posted 20 December 2013 - 06:55 AM

The problem is solved,i don't know why but for some strange reason (maybe not if someone knows the math behind quaternion,which i don't)

negating both Z and Y axis gave the correct results.

Basically now eveything is working with:

Quaternion rotation = new Quaternion(X, -Z, -Y, -W);


I tried before to negate one axe but instead of inverting the orientation,it was like swapping axis again.

Thanks.

### #5Álvaro  Crossbones+   -  Reputation: 9895

Like
0Likes
Like

Posted 20 December 2013 - 07:36 AM

You can try negating only X instead of Y, Z and W. Not that it matters much, but perhaps it's easier to think of what that does.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS