# Problem with euler to quaternion rotation

This topic is 2057 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
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633708
• Total Posts
3013468
×