- Home /

# How to flip one axis of a quaternion?

I can successfully read in values from an external IMU and I'm trying to visualize its orientation in Unity, but after I offset it one axis appears to be flipped and I don't know how to reverse it.

I'm reading the orientation in quaternion and I'm trying to avoid using Euler Angles (because of the gimbal lock). Is there a way to flip one axis of a quaternion using only its values (x, y, z, w)?

Do you mean like doing `float myAxis = -transform.rotation.x;`

**Answer** by LeventeXXL
·
Jan 21 at 09:09 AM

I figured it out eventually. I had to put in the values like x, -y, -z, w to flip the x axis, then had to take the inverse of the whole quaternion. Of course, this way I had to multiply it with the inverse of the offset to get the desired result.

**Answer** by ray2yar
·
Jan 20 at 05:13 PM

Well, lets say you wanted to change just the y axis in euler. You can get the euler angles directly from the quaternion using Quaternion.eulerAngles, and then switch it back using Quaternion.euler

I have already tried that, but then depending on how the IMU is oriented and how I offset it the axes change and flip unpredictable. It is only reliable if I don't convert it to euler angles and back, but then I don't know how to reverse one axis.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.