# Problem with euler to quaternion rotation

This topic is 1976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Basically I've got a GUI where the user can input euler angle rotations in degrees for X, Y and Z (so Pitch, Yaw, Roll).

Then I'm creating a quaternion based of these values with the directx function:

XMQuaternionRotationRollPitchYaw(DegToRad(newRotation.x), DegToRad(newRotation.y), DegToRad(newRotation.z));


DegToRad is my own wrapper function that does:

inline float DegToRad(const float& deg)
{
return float(deg * (PI / 180.0f));
}


Now the problem I'm having is when inputting 180 degrees as yaw my resulting quaternion looks like this:

{3,49459e-007, 0, 1, 0} (w, z, y, x order)

In my application it still works but then I'm writing that out to a text file as a floating point value and after reading it again my rotation gets completely messed up. Which I assume is because of this w-component. Any ideas what's wrong? Is it just a floating point precision problem ?

Edited by lipsryme

##### Share on other sites

What is the value after you read it back in? Is it 3.49459 by any chance (which would suggest the read function isn't coping with the exponent part correctly)? What function are you using to read it back in?

Note 3.49459e-007 is very close to zero (3.49459 * 10 ^ -7), you could just clamp it to zero using an epsilon before writing it out.

##### Share on other sites

The vector it's writing out is actually (0, 1, 0, 0) (xyzw). So it seems like it's already clamping this to zero.

Solved: Oh...it seems like there was some part of the code that did not read the w-component, so it was always 1.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 43
• ### Forum Statistics

• Total Topics
632635
• Total Posts
3007560
• ### Who's Online (See full list)

There are no registered users currently online

×