Is it possible to reverse 1 axis of a Quaternion? Quaternion.Inverse reverses all the data.
Would you have to convert to Euler then somehow back to Quaternion?
I’m getting quaternion orientation data from an external source but the Z data needs to be reversed and I read you’re not supposed to modify Quaternion data directly. (very difficult)
I dont want to use EulerAngles because of Gimbal Locking, would reprojecting it somehow (using Slerp?) fix that?
They're fully predictable, just they use complex 4D rotations. Inverting the Z of a quaternion won't necessarily invert the Z of the resulting euler angle. If you want to invert the euler angle then: var existing = rotation.eulerAngles; existing.z =-existing.z; rotation = Quaternion.Euler(existing);
I believe (having experience with Kinect & Unity3d) that what he wants is the same Rotation in a coordinate space where Z is inverted. That comes down to mirroring around the XY plane.
To mirror a quaternion around the XY plane, you need to negate the Z value and the W value.
Thank you. This is exactly what I was trying to do, and your simple explanation is everything I needed.
Because quaternions are stupid hard to deal with, that statement may mean anything.
D’you want the character to face the other way? Rotate by 180 around the Y axis.
You can rotate a quaternion by multiplying it by another quaternion. Say A is your facing you want to change, and B is Quaternion.AngleAxis(Vector3.up,180) (or whatever the syntax is). If you want to rotate A by 180 around Y, then: A = B * A.
edit: As noted in the comments, you’re perfectly free to alter the data in a quaternion. You just don’t know what that will do, unless you do know what that will do. If you’re getting bad z values, go ahead and fix 'em.
That's not an inversion. It's always best to say what you want to do :D You need to multiply it by something like: Quaternion.FromToRotation(Vector3.forward, Vector3.up);
I was suggesting that you do: leftShoulderRigObj.transform.rotation = Quaternion.FromToRotation(Vector3.forward, Vector3.up) * leftShoulderOrientation;
“Is it possible to reverse 1 axis of a quaternion?” I think you might be confusing the XYZ of a quaternion as being 3 axes, as with Euler angles. Instead, with quaternions, the XYZ describes a single axis that the rotation W is applied to. wikipedia overview
It sounds like you mean to ask “Suppose someone had converted Euler angles to a quaternion, and that’s all I have now. How do I get the quaternion for the same Euler angles with an inverted Z axis?”
Keep in mind that Quaternion.Euler “Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).”
If you’re after something different, it might help to diagram what you’re trying to do.
His question is actually not that bad, and is fully understandable if you have ever worked with sensor data on your on.
The point here is, IMU sensor data usually is calculated into quaternion data. This data can directly be applied to the GameObject Transform via euler angles:
where bodyQuaternion is the quaternion from the sensor data.
Now I create a simple Cube in unity and want it to behave like my sensor. Therefore, I have to exchange the quaternion values X and Y before. In my code, this looks like this:
With that, it works perfectly fine, except the fact that my view towards the sensor would be from “behind” in unity. Which means, if I turn it clockwise parallel to earth gravity axis (yaw), it turns counter-clockwise in Unity. I simply see it from the wrong side in my program.
Therefore, I want to invert the view axis Z in unity.
As I’m also new to Unity, I have no idea how to do best: Local axis of my cube? Another rotation with another quaternion for 180 degrees?
There were some good ideas above, and I will try them.
Are you receiving a quaternion or a euler angle?
– whydoidoitThen just invert the Z coordinate and it will be fine.
– whydoidoitPresuming you mean that the Z of the quaternion is inverted (not the Z of the resulting euler angle).
– whydoidoitThey're fully predictable, just they use complex 4D rotations. Inverting the Z of a quaternion won't necessarily invert the Z of the resulting euler angle. If you want to invert the euler angle then: var existing = rotation.eulerAngles; existing.z =-existing.z; rotation = Quaternion.Euler(existing);
– whydoidoit