- 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, 2019 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, 2019 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 I$$anonymous$$U 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
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Rotation of an Object yielding no results 1 Answer
help me to rotate an object 1 Answer